Skip to content

Commit f085fb2

Browse files
committed
Add object interaction example
1 parent 2ae5a06 commit f085fb2

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

source-code/command-line-arguments/Fire/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ applications with a command line interface.
1010
1. `sayer.py`: Illustration of grouped commands.
1111
1. `cl_logger.py`/`log_management.py`/`log_operations.py`: logging
1212
from the command line example.
13+
1. `job.py`: simple class definition to explore interacting with
14+
objects from the CLI.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
import fire
3+
4+
5+
class Job:
6+
7+
_nodes: int
8+
_ntasks: int
9+
10+
def __init__(self, nodes=1, ntasks=1):
11+
self.nodes = nodes
12+
self.ntasks = ntasks
13+
14+
@property
15+
def nodes(self):
16+
return self._nodes
17+
18+
@nodes.setter
19+
def nodes(self, nodes):
20+
self._nodes = nodes
21+
return self
22+
23+
24+
@property
25+
def ntasks(self):
26+
return self._ntasks
27+
28+
@ntasks.setter
29+
def ntasks(self, ntasks):
30+
self._ntasks = ntasks
31+
return self
32+
33+
def print(self):
34+
return f'nodes={self.nodes} ntasks={self.ntasks}'
35+
36+
if __name__ == '__main__':
37+
fire.Fire(Job)

0 commit comments

Comments
 (0)