@@ -5,74 +5,30 @@ import os,
55 strutils,
66 progress,
77 terminal,
8- commandeer,
98 strformat
109
11- const versionNum = staticRead (fmt" ../dye.nimble " ).splitLines ()[0 ].split (" =" )[1 ]
12- .strip ().replace (" \" " , " " )
10+ include ../ lib/ args
1311
14- const release = defined (release)
15-
16- var bType: string
17-
18- if release:
19- bType = " release"
20- else :
21- bType = " debug"
22-
23- commandline:
24- arguments dyefile, string
25- option dyebar, bool , " bar" , " b"
26- option dyeoutfile, string , " out" , " o" , " null"
27- option palette, string , " palette" , " p"
28- exitoption " v" , " version" , " dye v$#\n build: $#" % @ [versionNum, bType]
29- subcommand flip, " flip" , " f" :
30- arguments flipfile, string
31- option flipoutfile, string , " out" , " o" , " null"
32- option flipbar, bool , " bar" , " b"
33- subcommand luma, " luma" , " l" :
34- arguments lumafile, string
35- option lumaoutfile, string , " out" , " o" , " null"
36- option lumabar, bool , " bar" , " b"
37- subcommand helpcmd, " help" , " h" :
38- option command, string , " command" , " c" , " null"
39- subcommand list, " list" , " l" :
40- option x, bool , " X" , " x" , false # This doesnt actually do anything.
41-
42- discard x
43-
44- import ../ lib/ [colors, palettes, help]
45-
46- if helpcmd:
47- if command != " null" :
48- for k, v in helps.fieldPairs:
49- if k == command:
50- echo v
51- quit 0
52- stdout.styledWriteLine (fgRed, " Error: " , fgWhite, " Unknown command: " & command)
53- quit 0
54- else :
55- echo helps.all
56- quit 0
57-
58- var outfile: string
59- var bar: bool
60-
61- if flip:
62- outfile = flipoutfile
63- bar = flipbar
64- elif luma:
65- outfile = lumaoutfile
66- bar = lumabar
67- else :
68- outfile = dyeoutfile
69- bar = dyebar
12+ import ../ lib/ [colors, palettes]
7013
7114var
7215 flipName: string
7316 convName: string
7417 lumaName: string
7518
19+ var outfile: string
20+ var fileDir: string
21+
22+ if args.flip.seen:
23+ outfile = flip.output.value
24+ fileDir = flip.file.value
25+ elif args.luma.seen:
26+ outfile = luma.output.value
27+ fileDir = luma.file.value
28+ else :
29+ outfile = args.output.value
30+ fileDir = args.file.value
31+
7632proc fileName (file: string ): void =
7733 if outfile != " null" :
7834 flipName = outfile & " .png"
@@ -83,7 +39,12 @@ proc fileName(file: string): void =
8339 convName = " conv-" & getFilename (file) & " .png"
8440 lumaName = " luma-" & getFilename (file) & " .png"
8541
86- var imgs: seq [string ]
42+ var files: seq [string ]
43+ if dirExists (fileDir):
44+ for file in walkDir (fileDir):
45+ files.add (file.path)
46+ else :
47+ files.add (fileDir)
8748
8849proc flipCol (imgPath: string , bar: bool ): void =
8950 stdout.styledWriteLine (fgYellow, " Converting: " , fgWhite, splitFile (
@@ -190,39 +151,39 @@ proc col(imgPath: string, bar: bool, colors: seq[string]): void =
190151 stdout.styledWriteLine (fgGreen, " Completed: " , fgWhite, splitFile (
191152 imgPath).name & splitFile (imgPath).ext & " \n " )
192153
193- if flip:
194- for img in flipfile :
154+ if args. flip.seen :
155+ for img in files :
195156 try :
196- flipCol (img, bar)
157+ flipCol (img, flip. bar.seen )
197158 except :
198159 stdout.styledWriteLine (fgRed, " Error: " , fgWhite, getCurrentExceptionMsg ())
199160 continue
200- elif luma:
201- for img in lumafile :
161+ elif args. luma.seen :
162+ for img in files :
202163 try :
203- lumaCol (img, bar)
164+ lumaCol (img, luma. bar.seen )
204165 except :
205166 stdout.styledWriteLine (fgRed, " Error: " , fgWhite, getCurrentExceptionMsg ())
206167 continue
207- elif list:
168+ elif args. list.seen :
208169 for k, v in pal.fieldPairs:
209170 discard v
210171 echo k
211172else :
212173 var cols: seq [string ]
213- if " ," in palette:
214- cols = palette.parseColors ()
215- elif fileExists (palette):
216- cols = readFile (palette).parseColors ()
174+ if " ," in args. palette.value :
175+ cols = args. palette.value .parseColors ()
176+ elif fileExists (args. palette.value ):
177+ cols = readFile (args. palette.value ).parseColors ()
217178 else :
218179 for k, v in pal.fieldPairs:
219- if palette == k:
180+ if args. palette.value == k:
220181 cols = v
221182 break
222183 cols = cols.rmTag ()
223- for img in dyefile :
184+ for img in files :
224185 try :
225- col (img, bar, cols)
186+ col (img, args. bar.seen , cols)
226187 except :
227188 stdout.styledWriteLine (fgRed, " Error: " , fgWhite, getCurrentExceptionMsg ())
228189 continue
0 commit comments