Skip to content

Commit 75683b0

Browse files
committed
Improve example
1 parent 5d361cc commit 75683b0

File tree

1 file changed

+39
-7
lines changed
  • source-code/command-line-arguments/Fire

1 file changed

+39
-7
lines changed

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

+39-7
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,62 @@
44

55

66
class Hello:
7+
'''Hello group of commands, there is a to and a everyone
8+
command
9+
'''
710

811
def __init__(self, name):
912
self.name = name
1013

11-
def say(self):
12-
return f'Hello {self.name}'
14+
def to(self, name=None):
15+
if name is None:
16+
if self.name is None:
17+
return 'No one to say hello to'
18+
else:
19+
return f'Hello to {self.name}'
20+
else:
21+
return f'Hello {name}'
22+
23+
def everyone(self):
24+
return 'hello to everyone'
25+
1326

1427
class Bye:
28+
'''Bye group of commands, there is a to and a no_one
29+
command
30+
'''
1531

1632
def __init__(self, name):
1733
self.name = name
1834

19-
def say(self):
20-
return f'Bye {self.name}'
35+
def to(self, name=None):
36+
if name is None:
37+
if self.name is None:
38+
return 'No one to say bye to'
39+
else:
40+
return f'Bye to {self.name}'
41+
else:
42+
return f'Bye {name}'
43+
44+
def no_one(self):
45+
return f'Bye to no one'
2146

2247

2348
class Sayer:
49+
'''Class to make the hello and bye groups available, it
50+
also has its own to command, as well as the info command
51+
'''
2452

25-
def __init__(self, hello_name, bye_name):
53+
def __init__(self, hello_name=None, bye_name=None):
2654
self.hello = Hello(hello_name)
2755
self.bye = Bye(bye_name)
2856

29-
def say(self):
30-
return f'Bla, bla'
57+
def to(self):
58+
return 'Do you want to say hello or bye'
59+
60+
def info(self):
61+
return 'This is version 0.1beta'
62+
3163

3264
if __name__ == '__main__':
3365
fire.Fire(Sayer)

0 commit comments

Comments
 (0)