diff options
author | kitsunyan | 2018-05-31 07:00:31 +0000 |
---|---|---|
committer | kitsunyan | 2018-05-31 07:00:31 +0000 |
commit | 1fa779a2d7a88fe4e3e4bbc36605a7f30930ece6 (patch) | |
tree | e632eb938611f337daddc81fb8b89e3660f44967 /src | |
parent | 6220a954ef32fec18258b4feab6494aa016764e0 (diff) |
Don't parse and validate config when "--help" is used
Diffstat (limited to 'src')
-rw-r--r-- | src/main.nim | 59 | ||||
-rw-r--r-- | src/utils.nim | 4 |
2 files changed, 32 insertions, 31 deletions
diff --git a/src/main.nim b/src/main.nim index 1d35929..7171716 100644 --- a/src/main.nim +++ b/src/main.nim @@ -216,39 +216,40 @@ let init = withErrorHandler(none(bool), tuple[parsedArgs: seq[Argument], config: Config]): let parsedArgs = splitArgs(commandLineParams(), optionsWithParameter, (operations.map(o => o.pair.long) & allOptions.map(o => o.pair.long)).deduplicate) - let pacmanConfig = obtainPacmanConfig(parsedArgs) - let config = obtainConfig(pacmanConfig) - (parsedArgs, config) + let operation = getOperation(parsedArgs) + if operation != OperationType.invalid and + parsedArgs.check(%%%"help"): + handleHelp(operation) + raise haltError(0) + elif operation != OperationType.invalid and + parsedArgs.check((some("V"), "version")): + let code = handleVersion() + raise haltError(code) + else: + let pacmanConfig = obtainPacmanConfig(parsedArgs) + let config = obtainConfig(pacmanConfig) + (parsedArgs, config) proc run(parsedArgs: seq[Argument], config: Config): tuple[success: Option[int], code: int] = withErrorHandler(some(config.color), int): - let operation = getOperation(parsedArgs) - if operation != OperationType.invalid and - parsedArgs.check(%%%"help"): - handleHelp(operation) - 0 - elif operation != OperationType.invalid and - parsedArgs.check((some("V"), "version")): - handleVersion() - else: - case operation: - of OperationType.database: - handleDatabase(parsedArgs, config) - of OperationType.files: - handleFiles(parsedArgs, config) - of OperationType.query: - handleQuery(parsedArgs, config) - of OperationType.remove: - handleRemove(parsedArgs, config) - of OperationType.sync: - handleSync(parsedArgs, config) - of OperationType.deptest: - handleDeptest(parsedArgs, config) - of OperationType.upgrade: - handleUpgrade(parsedArgs, config) - else: - passValidation(parsedArgs, config, [], [], allOptions) + case getOperation(parsedArgs): + of OperationType.database: + handleDatabase(parsedArgs, config) + of OperationType.files: + handleFiles(parsedArgs, config) + of OperationType.query: + handleQuery(parsedArgs, config) + of OperationType.remove: + handleRemove(parsedArgs, config) + of OperationType.sync: + handleSync(parsedArgs, config) + of OperationType.deptest: + handleDeptest(parsedArgs, config) + of OperationType.upgrade: + handleUpgrade(parsedArgs, config) + else: + passValidation(parsedArgs, config, [], [], allOptions) let runResult = if init.success.isSome: run(init.success.unsafeGet.parsedArgs, init.success.unsafeGet.config) diff --git a/src/utils.nim b/src/utils.nim index 7dcf620..67bf140 100644 --- a/src/utils.nim +++ b/src/utils.nim @@ -41,10 +41,10 @@ const pacmanCmd* = "/usr/bin/pacman" makepkgCmd* = "/usr/bin/makepkg" -template haltError*(code: int): untyped = +template haltError*(exitCode: int): untyped = var e: ref HaltError new(e) - e.code = code + e.code = exitCode e template commandError*(message: string, colorNeeded: Option[bool] = none(bool), |