Commit ec7d961359cabb631d7769eb90aacd5d6d7d0262
1 parent
14d16aa7
Added option --filter and fixed some bugs.
Showing
1 changed file
with
26 additions
and
11 deletions
blimp.nim
... | ... | @@ -37,7 +37,7 @@ const |
37 | 37 | var |
38 | 38 | blimpStore, remoteBlimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat, rsyncPassword, blimpVersion: string = nil |
39 | 39 | homeDir, currentDir, gitRootDir: string |
40 | - verbose, stdio, inflateAll: bool | |
40 | + verbose, stdio, onAllDeflated, onAllFiltered: bool | |
41 | 41 | stdinContent: string = nil |
42 | 42 | |
43 | 43 | let |
... | ... | @@ -69,10 +69,8 @@ delete = "rsync --password-file $3/.blimp.pass -dv --delete --existing --ignore- |
69 | 69 | |
70 | 70 | [blimp] |
71 | 71 | # Minimal version, otherwise stop |
72 | -# version = 0.2 | |
73 | -""" | |
72 | +# version = """ & versionAsString | |
74 | 73 | |
75 | - | |
76 | 74 | |
77 | 75 | proc cmd(cmd: string): string = |
78 | 76 | try: |
... | ... | @@ -201,7 +199,7 @@ proc copyToBlimpStore(filename, blimpFilename: string) = |
201 | 199 | quit("Failed writing file: " & blimpStore / blimpFilename & " from stdin", 1) |
202 | 200 | else: |
203 | 201 | copyFile(filename, blimpStore / blimpFilename) |
204 | - uploadFile(blimpFilename) | |
202 | + uploadFile(blimpFilename) | |
205 | 203 | |
206 | 204 | # Copy content from blimpStore, and downloading first if needed |
207 | 205 | proc copyFromBlimpStore(blimpFilename, filename: string) = |
... | ... | @@ -270,6 +268,14 @@ iterator allDeflated() = |
270 | 268 | for fn in filenames: |
271 | 269 | if not blimpFilename(fn).isNil: |
272 | 270 | yield fn |
271 | + | |
272 | +# Iterator over all files matching the blimp filter in the git clone | |
273 | +iterator allFiltered() = | |
274 | + let lines = cmd("git ls-files | git check-attr --stdin filter").split('\l') | |
275 | + for line in lines: | |
276 | + let status = line.split(':') | |
277 | + if strip(status[2]) == "blimp": | |
278 | + yield status[0] | |
273 | 279 | |
274 | 280 | # Parse out hash from hash stub and copy back original content from blimpStore. |
275 | 281 | proc inflate(filename: string) = |
... | ... | @@ -329,6 +335,7 @@ let synopsis = """ |
329 | 335 | ---------- |
330 | 336 | <command> (string) (d)eflate, (i)nflate, remove |
331 | 337 | -a,--all Operate on all deflated files in clone |
338 | + -f,--filter Operate on all files matching blimp filter | |
332 | 339 | ---------- |
333 | 340 | -s,--stdio If given, use stdin/stdout for content. |
334 | 341 | <filenames> (string...) One or more filepaths to inflate/deflate |
... | ... | @@ -387,7 +394,7 @@ let help = """ |
387 | 394 | In order to have blimp work automatically you can: |
388 | 395 | |
389 | 396 | * Create a .gitattributes file with lines like: |
390 | - *.png filter=blimp -text | |
397 | + *.png filter=blimp binary | |
391 | 398 | |
392 | 399 | * Configure blimp as a filter by running: |
393 | 400 | git config filter.blimp.clean "blimp -s d %f" |
... | ... | @@ -418,7 +425,8 @@ gitRootDir = gitRoot() |
418 | 425 | var args = parse(synopsis) |
419 | 426 | verbose = args["verbose"].asBool |
420 | 427 | stdio = args["stdio"].asBool |
421 | -inflateAll = args["all"].asBool | |
428 | +onAllDeflated = args["all"].asBool | |
429 | +onAllFiltered = args["filter"].asBool | |
422 | 430 | |
423 | 431 | # Can't do verbose with -s, that messes up stdout, |
424 | 432 | # read in all of stdin once and for all |
... | ... | @@ -471,12 +479,19 @@ setupBlimpStore() |
471 | 479 | # Do the deed |
472 | 480 | if command != "": |
473 | 481 | if command == "d" or command == "deflate": |
474 | - for fn in filenames: | |
475 | - deflate(fn.asString) | |
482 | + if onAllFiltered: | |
483 | + for fn in allFiltered(): | |
484 | + deflate(fn) | |
485 | + else: | |
486 | + for fn in filenames: | |
487 | + deflate(fn.asString) | |
476 | 488 | elif command == "i" or command == "inflate": |
477 | - if inflateAll: | |
489 | + if onAllDeflated: | |
478 | 490 | for fn in allDeflated(): |
479 | 491 | inflate(fn) |
492 | + elif onAllFiltered: | |
493 | + for fn in allFiltered(): | |
494 | + inflate(fn) | |
480 | 495 | else: |
481 | 496 | for fn in filenames: |
482 | 497 | inflate(fn.asString) |
... | ... | @@ -484,7 +499,7 @@ if command != "": |
484 | 499 | for fn in filenames: |
485 | 500 | remove(fn.asString) |
486 | 501 | else: |
487 | - quit("Unknown command, only (d)eflate or (i)inflate are valid.", 6) | |
502 | + quit("Unknown command, only (d)eflate, (i)inflate or remove are valid.", 6) | |
488 | 503 | |
489 | 504 | # All good |
490 | 505 | quit(0) | ... | ... |