Skip to content

shargs-example-async-deepthought is a sample application of shargs 🦈.

License

Notifications You must be signed in to change notification settings

Yord/shargs-example-async-deepthought

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shargs-example-async-deepthought is a sample application of shargs 🦈.

See the shargs github repository for more details!

node version license PRs Welcome

Setup

$ git clone https://github.com/Yord/shargs-example-async-deepthought.git
$ cd shargs-example-async-deepthought
$ npm i
$ chmod +x ./deepThought

Example

This repository is a simple example of a program using the shargs command-line parser. The program can be found in the deepThought script.

Run the Example

The example may be run with different parameters:

Printing Usage Documentation

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.                                             

The Answer to the Ultimate Question

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
}

Error Output

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.

Reporting Issues

Please report issues in the shargs tracker!

License

shargs-example-async-deepthought is MIT licensed.

About

shargs-example-async-deepthought is a sample application of shargs 🦈.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks