Skip to content

Instantly share code, notes, and snippets.

@akarsh1995
Created August 27, 2020 17:10
Show Gist options
  • Select an option

  • Save akarsh1995/07b6441413d9b6d6c836a2b5527c60ea to your computer and use it in GitHub Desktop.

Select an option

Save akarsh1995/07b6441413d9b6d6c836a2b5527c60ea to your computer and use it in GitHub Desktop.
Dispatch function as commandline utility. But this time using argh.
#! python
import argh
# declaring:
def echo(text):
"Returns given word as is."
return text
def greet(name, greeting='Hello'):
"Greets the user with given name.
The greeting is customizable."
return greeting + ', ' + name
# assembling:
parser = argh.ArghParser()
parser.add_commands([echo, greet])
# dispatching:
if __name__ == '__main__':
parser.dispatch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment