Skip to content

Commit

Permalink
Allow offline create
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Jan 18, 2024
1 parent 1035394 commit 26bfed4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type
# in `actSync`, and Nim doesn't yet support duplicate field names
# in object variants.
exerciseCreate*: string
offlineCreate*: bool
of actFmt:
# We can't name these fields `exercise`, `update`, and `yes` because we
# use those names in `actSync`, and Nim doesn't yet support duplicate
Expand Down Expand Up @@ -98,8 +99,8 @@ type
optFmtSyncUpdate = "update"
optFmtSyncYes = "yes"

# Options for both `info` and `sync`
optInfoSyncOffline = "offline"
# Options for both `info`, `sync` and `create`
optInfoSyncCreateOffline = "offline"

# Scope to sync
optSyncDocs = "docs"
Expand All @@ -124,7 +125,7 @@ const
configletVersion = staticRead("../configlet.version").strip()
short = genShortKeys()
optsNoVal = {optHelp, optVersion, optFmtSyncUpdate, optFmtSyncYes,
optInfoSyncOffline, optSyncDocs, optSyncFilepaths, optSyncMetadata}
optInfoSyncCreateOffline, optSyncDocs, optSyncFilepaths, optSyncMetadata}

func generateNoVals: tuple[shortNoVal: set[char], longNoVal: seq[string]] =
## Returns the short and long keys for the options in `optsNoVal`.
Expand Down Expand Up @@ -248,7 +249,7 @@ func genHelpText: string =
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",
optInfoSyncOffline: "Do not update the cached 'problem-specifications' data",
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",
Expand Down Expand Up @@ -313,7 +314,9 @@ func genHelpText: string =
of "yesFmt":
optFmtSyncYes
of "offlineInfo":
optInfoSyncOffline
optInfoSyncCreateOffline
of "offlineCreate":
optInfoSyncCreateOffline
else:
parseEnum[Opt](key)
# Set the description for `fmt` options.
Expand Down Expand Up @@ -547,6 +550,8 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
setActionOpt(conceptExerciseSlug, val)
of optCreatePracticeExercise:
setActionOpt(practiceExerciseSlug, val)
of optInfoSyncCreateOffline:
setActionOpt(offlineCreate, true)
else:
discard
of actFmt:
Expand All @@ -561,7 +566,7 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
discard
of actInfo:
case opt
of optInfoSyncOffline:
of optInfoSyncCreateOffline:
setActionOpt(offlineInfo, true)
else:
discard
Expand All @@ -576,7 +581,7 @@ proc handleOption(conf: var Conf; kind: CmdLineKind; key, val: string) =
of optSyncTests:
setActionOpt(tests, parseVal[TestsMode](kind, key, val))
conf.action.scope.incl skTests
of optInfoSyncOffline:
of optInfoSyncCreateOffline:
setActionOpt(offline, true)
of optSyncDocs, optSyncMetadata, optSyncFilepaths:
conf.action.scope.incl parseEnum[SyncKind]($opt)
Expand Down
1 change: 1 addition & 0 deletions src/create/exercises.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ proc syncExercise(conf: Conf, slug: Slug,) =
let syncConf = Conf(
trackDir: conf.trackDir,
action: Action(exercise: $slug, kind: actSync, update: true, yes: true,
offline: conf.action.offlineCreate,
scope: {skDocs, skFilepaths, skMetadata, skTests}, tests: tmInclude)
)
discard syncImpl(syncConf)
Expand Down
3 changes: 2 additions & 1 deletion src/sync/probspecs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ proc getNameOfRemote*(probSpecsDir: ProbSpecsDir;

func isOffline(conf: Conf): bool =
(conf.action.kind == actSync and conf.action.offline) or
(conf.action.kind == actInfo and conf.action.offlineInfo)
(conf.action.kind == actInfo and conf.action.offlineInfo) or
(conf.action.kind == actCreate and conf.action.offlineCreate)

proc validate(probSpecsDir: ProbSpecsDir, conf: Conf) =
## Raises an error if the given `probSpecsDir` is not a valid
Expand Down

0 comments on commit 26bfed4

Please sign in to comment.