Created
August 27, 2020 17:10
-
-
Save akarsh1995/07b6441413d9b6d6c836a2b5527c60ea to your computer and use it in GitHub Desktop.
Dispatch function as commandline utility. But this time using argh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| argh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! 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