diff options
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), |