diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2012-11-13 20:57:36 +0100 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2012-11-13 22:27:13 +0100 |
commit | 2faf34b643944b3f93b895aaf3e773e6b9dd78fe (patch) | |
tree | 68fa17c64b0f020a0ac89a50c798ab89248c44da /examples/cross_calculator/nimrod_commandline | |
parent | a31a5f9c810948b232356b7fe225b238dad0d6d6 (diff) | |
download | Nim-2faf34b643944b3f93b895aaf3e773e6b9dd78fe.tar.gz |
Improves the style of some examples.
* Compacts all imports in a single line. * Cleans whitespace before colons. * Uses cmd abbreviation for command line enums. * Replaces if/elif/else chain with case.
Diffstat (limited to 'examples/cross_calculator/nimrod_commandline')
-rw-r--r-- | examples/cross_calculator/nimrod_commandline/nimcalculator.nim | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/examples/cross_calculator/nimrod_commandline/nimcalculator.nim b/examples/cross_calculator/nimrod_commandline/nimcalculator.nim index 1fc62fa87..6f23b0556 100644 --- a/examples/cross_calculator/nimrod_commandline/nimcalculator.nim +++ b/examples/cross_calculator/nimrod_commandline/nimcalculator.nim @@ -1,8 +1,6 @@ # Implements a command line interface against the backend. -import backend -import parseopt -import strutils +import backend, parseopt, strutils const USAGE = """nimcalculator - Nimrod cross platform calculator @@ -19,12 +17,12 @@ If no options are used, an interactive mode is entered. """ type - TAction = enum # The possible types of operation - rtParams, # Two valid parameters were provided - rtInteractive # No parameters were provided, run interactive mode + TCommand = enum # The possible types of operation + cmdParams, # Two valid parameters were provided + cmdInteractive # No parameters were provided, run interactive mode TParamConfig = object of TObject - action: TAction # store the type of operation + action: TCommand # store the type of operation paramA, paramB: int # possibly store the valid parameters @@ -37,9 +35,9 @@ proc parseCmdLine(): TParamConfig = hasA = false hasB = false p = initOptParser() - key, val : TaintedString + key, val: TaintedString - result.action = rtInteractive # By default presume interactive mode. + result.action = cmdInteractive # By default presume interactive mode. try: while true: next(p) @@ -70,7 +68,7 @@ proc parseCmdLine(): TParamConfig = quit("Invalid value " & val & " for parameter " & key, 3) if hasA and hasB: - result.action = rtParams + result.action = cmdParams elif hasA or hasB: stdout.write(USAGE) quit("Error: provide both A and B to operate in param mode", 4) @@ -102,7 +100,7 @@ proc interactiveMode() = when isMainModule: ## Main entry point. let opt = parseCmdLine() - if rtParams == opt.action: + if cmdParams == opt.action: echo("Param mode: $1 + $2 = $3" % [$opt.paramA, $opt.paramB, $backend.myAdd(opt.paramA, opt.paramB)]) else: |