shargs-example-async-deepthought is a sample application of shargs 🦈.
See the shargs
github repository for more details!
$ git clone https://github.com/Yord/shargs-example-async-deepthought.git
$ cd shargs-example-async-deepthought
$ npm i
$ chmod +x ./deepThought
This 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 --help
Prints 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 --help
Prints 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 23
Prints the following error:
RequiredOptionMissing: An option that is marked as required has not been provided.
Providing a wrong --format
:
$ ./deepThought ask --format csv
Prints 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-async-deepthought
is MIT licensed.