11import
22 std/ [json, options, os, parseopt, strutils, terminal],
33 pkg/ puppy,
4- ./ info, ./ parser, ./ utils, ./ webapi,
4+ ./ info,
5+ ./ parser,
6+ ./ utils,
7+ ./ webapi,
58 ./ subcommands/ create
69
7-
8- type
9- Options = ref object of RootObj
10- command: string
11- targets: seq [string ]
12- # # Command targets
13- dest: Option [string ]
14- # # If value is set, out into file fo dest instead of STDOUT
15-
10+ type Options = ref object of RootObj
11+ command: string
12+ targets: seq [string ] # # Command targets
13+ dest: Option [string ] # # If value is set, out into file fo dest instead of STDOUT
1614
1715proc parseArgs (params: seq [string ]): Options =
1816 result = Options (command: " create" , targets: @ [], dest: none (string ))
1917 var p = initOptParser (params)
2018 while true :
2119 p.next ()
22- case p.kind:
23- of cmdEnd: break
24- of cmdLongOption, cmdShortOption:
25- if p.key == " h " or p.key == " help " :
26- result .command = " help"
27- break
28- if p.key == " o " or p.key == " out " :
29- result .dest = some (p.val)
30- of cmdArgument:
31- result .targets. add (p.key)
32-
20+ case p.kind
21+ of cmdEnd:
22+ break
23+ of cmdLongOption, cmdShortOption :
24+ if p.key == " h " or p.key == " help" :
25+ result .command = " help "
26+ break
27+ if p.key == " o " or p.key == " out " :
28+ result .dest = some (p.val)
29+ of cmdArgument:
30+ result .targets. add (p.key)
3331
3432proc main * (): int =
3533 result = 1
36- let
37- options = parseArgs (commandLineParams ())
38- var
39- targets = deepCopy (options.targets)
34+ let options = parseArgs (commandLineParams ())
35+ var targets = deepCopy (options.targets)
4036
4137 if options.command == " help" :
4238 result = 0
4339 stdout.writeLine (PKG_NAME & " version " & PKG_VERSION )
44- stdout.writeLine (" Usage: " & getAppName () & " [-h/--help] [-o/--out output] (TARGETS)" )
40+ stdout.writeLine (
41+ " Usage: " & getAppName () & " [-h/--help] [-o/--out output] (TARGETS)"
42+ )
4543 stdout.writeLine (" " )
4644 stdout.writeLine (" -h/--help Display help text" )
4745 stdout.writeLine (" -o/--out Write output instead of STDOUT" )
@@ -56,23 +54,23 @@ proc main*(): int =
5654
5755 if targets.len == 0 :
5856 stderr.writeLine (" No targets is specified." )
59-
6057
6158 try :
6259 let
6360 content = fetchContentOrCache ()
6461 templates = parseGitignoreTable (content.parseJson ())
65- var
66- strm =
67- if isNone (options.dest):
68- stdout
69- else :
70- open (options.dest.get (), fmWrite, - 1 )
62+ var strm =
63+ if isNone (options.dest):
64+ stdout
65+ else :
66+ open (options.dest.get (), fmWrite, - 1 )
7167 result = strm.outputGitignore (templates, targets)
7268 except PuppyError :
7369 let ex = getCurrentException ()
7470 stderr.writeLine (" Failured to fetch ignore templates." )
75- stderr.writeLine (" Please see error messages and check your environment if you need." )
71+ stderr.writeLine (
72+ " Please see error messages and check your environment if you need."
73+ )
7674 stderr.writeLine (" Message: " & ex.msg)
7775 return
7876
0 commit comments