Skip to content

Commit 53b5e09

Browse files
committed
Add Google Fire example
1 parent 3318103 commit 53b5e09

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

Diff for: source-code/command-line-arguments/Fire/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Fire
2+
3+
The Google Fire library can be used to (almost) effortlessly create
4+
applications with a command line interface.
5+
6+
## What is it?
7+
8+
1. `calculator.py`: Calculator application that implements addition
9+
and multiplication.
10+
1. `sayer.py`: Illustration of grouped commands.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
import fire
3+
4+
5+
def add(x, y):
6+
return x + y
7+
8+
def mult(x, y):
9+
return x*y
10+
11+
12+
if __name__ == '__main__':
13+
fire.Fire()

Diff for: source-code/command-line-arguments/Fire/sayer.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
3+
import fire
4+
5+
6+
class Hello:
7+
8+
def __init__(self, name):
9+
self.name = name
10+
11+
def say(self):
12+
return f'Hello {self.name}'
13+
14+
class Bye:
15+
16+
def __init__(self, name):
17+
self.name = name
18+
19+
def say(self):
20+
return f'Bye {self.name}'
21+
22+
23+
class Sayer:
24+
25+
def __init__(self, hello_name, bye_name):
26+
self.hello = Hello(hello_name)
27+
self.bye = Bye(bye_name)
28+
29+
def say(self):
30+
return f'Bla, bla'
31+
32+
if __name__ == '__main__':
33+
fire.Fire(Sayer)

Diff for: source-code/command-line-arguments/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ How to handle command line arguments in Python scripts.
77
to handle command line arguments.
88
1. `Click`: illustration of how to use the click module
99
to handle command line arguments.
10+
1. `Fire`: command line applications using Google Fire.

0 commit comments

Comments
 (0)