Skip to content

Commit

Permalink
README, cli: prepare to make generate consistent with sync and fmt
Browse files Browse the repository at this point in the history
We must still at least:

- alter `generate.nim`
- update the tests accordingly

Refs: 334
Refs: 542
  • Loading branch information
ee7 authored and ErikSchierboom committed Aug 16, 2024
1 parent 3baa096 commit 0706be0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ Options for fmt:
-u, --update Prompt to write formatted files
-y, --yes Auto-confirm the prompt from --update
Options for generate:
-e, --exercise <slug> Only operate on this exercise
-u, --update Prompt to write generated files
-y, --yes Auto-confirm the prompt from --update
Options for info:
-o, --offline Do not update the cached 'problem-specifications' data
Expand Down
78 changes: 48 additions & 30 deletions src/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type

Action* = object
case kind*: ActionKind
of actNil, actGenerate, actLint:
of actNil, actLint:
discard
of actCompletion:
shell*: Shell
Expand All @@ -56,6 +56,10 @@ type
exerciseFmt*: string
updateFmt*: bool
yesFmt*: bool
of actGenerate:
exerciseGenerate*: string
updateGenerate*: bool
yesGenerate*: bool
of actInfo:
offlineInfo*: bool
of actSync:
Expand Down Expand Up @@ -96,12 +100,12 @@ type
# Options for `completion`
optCompletionShell = "shell"

# Options for `create`, `fmt` and `sync`
optFmtSyncCreateExercise = "exercise"
# Options for `create`, `fmt`, generate, and `sync`
optFmtGenerateSyncCreateExercise = "exercise"

# Options for both `fmt` and `sync`
optFmtSyncUpdate = "update"
optFmtSyncYes = "yes"
# Options for `fmt`, `generate`, and `sync`
optFmtGenerateSyncUpdate = "update"
optFmtGenerateSyncYes = "yes"

# Options for both `info`, `sync` and `create`
optInfoSyncCreateOffline = "offline"
Expand All @@ -128,7 +132,7 @@ func genShortKeys: array[Opt, char] =
const
configletVersion = staticRead("../configlet.version").strip()
short = genShortKeys()
optsNoVal = {optHelp, optVersion, optFmtSyncUpdate, optFmtSyncYes,
optsNoVal = {optHelp, optVersion, optFmtGenerateSyncUpdate, optFmtGenerateSyncYes,
optInfoSyncCreateOffline, optSyncDocs, optSyncFilepaths, optSyncMetadata}

func generateNoVals: tuple[shortNoVal: set[char], longNoVal: seq[string]] =
Expand Down Expand Up @@ -186,7 +190,7 @@ func genHelpText: string =
of optTrackDir: "dir"
of optVerbosity: "verbosity"
of optCompletionShell: "shell"
of optFmtSyncCreateExercise: "slug"
of optFmtGenerateSyncCreateExercise: "slug"
of optCreateApproach: "slug"
of optCreateArticle: "slug"
of optCreateConceptExercise: "slug"
Expand Down Expand Up @@ -252,15 +256,15 @@ func genHelpText: string =
optCreateDifficulty: "The difficulty of the exercise (default: 1)",
optCompletionShell: &"Choose the shell type (required)\n" &
&"{paddingOpt}{allowedValues(Shell)}",
optFmtSyncCreateExercise: "Only operate on this exercise",
optFmtSyncUpdate: "Prompt to update the unsynced track data",
optFmtSyncYes: &"Auto-confirm prompts from --{$optFmtSyncUpdate} for updating docs, filepaths, and metadata",
optFmtGenerateSyncCreateExercise: "Only operate on this exercise",
optFmtGenerateSyncUpdate: "Prompt to update the unsynced track data",
optFmtGenerateSyncYes: &"Auto-confirm prompts from --{$optFmtGenerateSyncUpdate} for updating docs, filepaths, and metadata",
optInfoSyncCreateOffline: "Do not update the cached 'problem-specifications' data",
optSyncDocs: "Sync Practice Exercise '.docs/introduction.md' and '.docs/instructions.md' files",
optSyncFilepaths: "Populate empty 'files' values in Concept/Practice exercise '.meta/config.json' files",
optSyncMetadata: "Sync Practice Exercise '.meta/config.json' metadata values",
optSyncTests: &"Sync Practice Exercise '.meta/tests.toml' files.\n" &
&"{paddingOpt}The mode value specifies how missing tests are handled when using --{$optFmtSyncUpdate}.\n" &
&"{paddingOpt}The mode value specifies how missing tests are handled when using --{$optFmtGenerateSyncUpdate}.\n" &
&"{paddingOpt}{allowedValues(TestsMode)} (default: choose)",
optUuidNum: "Number of UUIDs to output",
]
Expand Down Expand Up @@ -312,13 +316,13 @@ func genHelpText: string =
of "practiceExerciseSlug":
optCreatePracticeExercise
of "exerciseCreate":
optFmtSyncCreateExercise
of "exerciseFmt":
optFmtSyncCreateExercise
of "updateFmt":
optFmtSyncUpdate
of "yesFmt":
optFmtSyncYes
optFmtGenerateSyncCreateExercise
of "exerciseFmt", "exerciseGenerate":
optFmtGenerateSyncCreateExercise
of "updateFmt", "updateGenerate":
optFmtGenerateSyncUpdate
of "yesFmt", "yesGenerate":
optFmtGenerateSyncYes
of "offlineInfo":
optInfoSyncCreateOffline
of "offlineCreate":
Expand All @@ -327,10 +331,14 @@ func genHelpText: string =
parseEnum[Opt](key)
# Set the description for `fmt` options.
let desc =
if actionKind == actFmt and opt == optFmtSyncUpdate:
if actionKind == actFmt and opt == optFmtGenerateSyncUpdate:
"Prompt to write formatted files"
elif actionKind == actFmt and opt == optFmtSyncYes:
&"Auto-confirm the prompt from --{$optFmtSyncUpdate}"
elif actionKind == actFmt and opt == optFmtGenerateSyncYes:
&"Auto-confirm the prompt from --{$optFmtGenerateSyncUpdate}"
elif actionKind == actGenerate and opt == optFmtGenerateSyncUpdate:
"Prompt to write generated files"
elif actionKind == actGenerate and opt == optFmtGenerateSyncYes:
&"Auto-confirm the prompt from --{$optFmtGenerateSyncUpdate}"
else:
optionDescriptions[opt]
result.add alignLeft(syntax[opt], maxLen) & desc & "\n"
Expand Down Expand Up @@ -536,7 +544,7 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
# Process action-specific options
if not isGlobalOpt:
case conf.action.kind
of actNil, actGenerate, actLint:
of actNil, actLint:
discard
of actCompletion:
case opt
Expand All @@ -550,7 +558,7 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
setActionOpt(approachSlug, val)
of optCreateArticle:
setActionOpt(articleSlug, val)
of optFmtSyncCreateExercise:
of optFmtGenerateSyncCreateExercise:
setActionOpt(exerciseCreate, val)
of optCreateConceptExercise:
setActionOpt(conceptExerciseSlug, val)
Expand All @@ -571,14 +579,24 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
discard
of actFmt:
case opt
of optFmtSyncCreateExercise:
of optFmtGenerateSyncCreateExercise:
setActionOpt(exerciseFmt, val)
of optFmtSyncUpdate:
of optFmtGenerateSyncUpdate:
setActionOpt(updateFmt, true)
of optFmtSyncYes:
of optFmtGenerateSyncYes:
setActionOpt(yesFmt, true)
else:
discard
of actGenerate:
case opt
of optFmtGenerateSyncCreateExercise:
setActionOpt(exerciseGenerate, val)
of optFmtGenerateSyncUpdate:
setActionOpt(updateGenerate, true)
of optFmtGenerateSyncYes:
setActionOpt(yesGenerate, true)
else:
discard
of actInfo:
case opt
of optInfoSyncCreateOffline:
Expand All @@ -587,11 +605,11 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
discard
of actSync:
case opt
of optFmtSyncCreateExercise:
of optFmtGenerateSyncCreateExercise:
setActionOpt(exercise, val)
of optFmtSyncUpdate:
of optFmtGenerateSyncUpdate:
setActionOpt(update, true)
of optFmtSyncYes:
of optFmtGenerateSyncYes:
setActionOpt(yes, true)
of optSyncTests:
setActionOpt(tests, parseVal[TestsMode](kind, key, val))
Expand Down

0 comments on commit 0706be0

Please sign in to comment.