24 lines
559 B
Markdown
24 lines
559 B
Markdown
|
|
Python [fire](https://github.com/google/python-fire) is extremely useful for automatically generating command line interfaces (CLIs) from absolutely any Python object.
|
|
|
|
Examples:
|
|
|
|
The python class:
|
|
```python
|
|
import fire
|
|
|
|
class Calculator(object):
|
|
"""A simple calculator class."""
|
|
|
|
def double(self, number):
|
|
return 2 * number
|
|
|
|
if __name__ == '__main__':
|
|
fire.Fire(Calculator)
|
|
```
|
|
|
|
Then, when calling the file on the terminal, the CLI is already there:
|
|
```shell
|
|
python calculator.py double 10 # 20
|
|
python calculator.py double --number=15 # 30
|
|
``` |