1.6.1 • Published 7 months ago
@magicdawn/x-args v1.6.1
x-args
play with cli commands like a composer
Install
$ pnpm add @magicdawn/x-args -g
# or
$ pnpm dlx @magicdawn/x-args
$ pnpx @magicdawn/x-args
$ bunx @magicdawn/x-argsCommands
x-args command
x-args -f './*.*' -c $'cwebp :file -o \':dir/:name_compressed.:ext\''use -t to show available tokens
txt sub command
# use :line
x-args txt ./to-be-processed.txt -c 'echo :line'features that native xargs does not have
- comment,
x-args txtsupport//or#comment, I suggest use.confextenstion, so that editors can recognize#comment - live reload,
x-args txtread txt file, exec command, and read txt again, so edit after command start will works as well - wait input update: use
-w,--wait, so that this command will not exit but to wait txt file update. use--wait-timeout 1hto delay1h1 hour.
Templates
- use
:linefor whole line - use
:args0/:arg0for single arg - use
-s/--split/--args-splitto specify how to turn:lineto:args0, default using/\s+/
when input is a filepath, and may contains space, use a different separator that has low possibility occurs in a filepath for example
- ancient chinese character for Simplified chinese user:
__纛恚掾旒__,--args-split '__纛恚掾旒__', 出处 - english user, maybe a emoji combination ?
Tips
-c,--command
if need single quote in -c,--command, u can use -c $'command \'inside-a-quote\'', a special shell syntax learn from zx, see
:line / :arg0
this will be auto escaped, no need to manual quote, just use plain :line / :arg0
retry
if your -c,--command may fail, and u need retry it. u can use https://npm.im/retry-cli
# install globally
pnpm add -g retry-cli
# add retry to `command-may-fail`
x-args txt ./to-be-processed.txt -c 'retry -- command-may-fail :line'
# retry times 1000, default: 10, see retry-cli homepage
x-args txt ./to-be-processed.txt -c 'retry -n 1000 -- command-may-fail :line'Changelog
License
the MIT License http://magicdawn.mit-license.org