janet-lang / argparse Goto Github PK
View Code? Open in Web Editor NEWCLI argument parser for Janet
License: MIT License
CLI argument parser for Janet
License: MIT License
As the functionality of this package is also present in the spork package, I would consider deprecating it and redirect any future users to spork.
My only reason is not to have duplicate work if we find any bugs or improvements.
Although (doc argparse/argparse)
says
There is also a special option :default that will be invoked on arguments that do not start with a -- or -. Use this option to collect unnamed arguments to your script.
I cannot figure out how to translate this explanation into code.
(argparse "..." :default)
doesn't really capture unnamed arguments.
I want to explain how unnamed arguments are handled in help.
This is my whenSafe
script.
#!/usr/bin/env janet
(import argparse)
(let [{"script" scripts "pager" pager :default cmd-args}
(argparse/argparse
(string "If all scripts execute successfully, execute arguments.\n"
"Usage: whenSafe -s script1 -s script2 -s ... -p pager "
"cmd cmd-amrgs...")
"script" {:kind :accumulate
:short "s"
:required true
:help (string "If its exit code is not zero, "
"its standard output is printed to pager.")}
"pager" {:kind :option
:short "p"
:required true
:help "The pager used to notify errors."}
:default {:kind :accumulate
:required true
:help "command to execute"})]
(pp scripts)
(pp pager)
(pp cmd-args))
Execute ./whenSafe -s script1 -s script2 -p pager echo ok
.
@["script1" "script2"]
"pager"
@["echo" "ok"]
Execute ./whenSafe -s script1 -s script2 -p pager -- echo -n ok
.
usage error: unknown option
usage: ./whenSafe [option] ...
If all scripts execute successfully, execute arguments.
Usage: whenSafe -s script1 -s script2 -s ... -p pager cmd cmd-amrgs...
Required:
-p, --pager VALUE The pager used to notify errors.
-s, --script VALUE If its exit code is not zero, its standard output is printed to pager.
Optional:
-h, --help Show this help message.
error: expected string|symbol|keyword|array|tuple|table|struct|buffer, got nil
in _thunk [./whenSafe] (tailcall) on line 4, column 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.