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/main.nim | |
parent | 6220a954ef32fec18258b4feab6494aa016764e0 (diff) |
Don't parse and validate config when "--help" is used
Diffstat (limited to 'src/main.nim')
-rw-r--r-- | src/main.nim | 59 |
1 files changed, 30 insertions, 29 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) |