shargs-example-sync-deepthought is a sample application of shargs 🦈.
See the shargs github repository for more details!
$ git clone https://github.com/Yord/shargs-example-sync-deepthought.git
$ cd shargs-example-sync-deepthought
$ npm i
$ chmod +x ./deepThoughtThis repository is a simple example of a program using the shargs command-line parser.
The program can be found in the deepThought script.
The example may be run with different parameters:
Providing a --help flag:
$ ./deepThought --helpPrints the following text to the console:
deepThought [-a|--answer] [-h|--help]
deepThought ask [--format] [--no-html] [-h|--help] (<question>)
-a, --answer=<number> The answer. [default: 42]
-h, --help Print this help message and exit.
ask Ask a question. [required]
--format=<json|xml> Respond either with json or xml. [default: json]
--no-html Removes HTML tags.
-h, --help Print this help message and exit.
<question> State your question. [required]
Deep Thought was created to come up with the Answer to The Ultimate Question of
Life, the Universe, and Everything. Providing ask --help:
$ ./deepThought ask --helpPrints text in a different usage format:
deepThought ask [--format] [--no-html] [-h|--help] (<question>)
--format=<json|xml> [default: json]
Respond either with json or xml.
--no-html
Removes HTML tags.
-h, --help
Print this help message and exit.
<question> [required]
State your question.
Deep Thought was created to come up with the Answer to The Ultimate Question of
Life, the Universe, and Everything. Providing ask with a question:
$ ./deepThought ask "What is the meaning of life, the universe, and everything?"Prints the following text to the console:
The answer is: 42
{
"_": [],
"ask": {
"_": [],
"format": "json",
"question": "What is the meaning of life, the universe, and everything?"
},
"answer": 42
}Providing no ask command:
$ ./deepThought --answer 23Prints the following error:
RequiredOptionMissing: An option that is marked as required has not been provided.Providing a wrong --format:
$ ./deepThought ask --format csvPrints the following error:
RequiredOptionMissing: An option that is marked as required has not been provided.
ValueRestrictionsViolated: A value lies outside the allowed values of an option.Please report issues in the shargs tracker!
shargs-example-sync-deepthought is MIT licensed.