MCPcopy Create free account
hub / github.com/SpaceNetLab/StarryNet / CLI

Class CLI

starrynet/cli.py:38–252  ·  view source on GitHub ↗

Simple command-line interface to talk to nodes.

Source from the content-addressed store, hash-verified

36
37
38class CLI(Cmd):
39 "Simple command-line interface to talk to nodes."
40
41 prompt = 'starrynet> '
42
43 def __init__(self, starrynet, stdin=sys.stdin, *args, **kwargs):
44 """Start and run interactive or batch mode CLI
45 starrynet: Starrynet network object
46 stdin: standard input for CLI
47 script: script to run in batch mode"""
48 self.sn = starrynet
49 # Local variable bindings for py command
50 self.locals = {'net': starrynet}
51 # Attempt to handle input
52 self.inPoller = poll()
53 self.inPoller.register(stdin)
54 Cmd.__init__(self, *args, stdin=stdin, **kwargs)
55 info('*** Starting CLI:\n')
56
57 self.run()
58
59 def run(self):
60 "Run our cmdloop(), catching KeyboardInterrupt"
61 while True:
62 try:
63 self.cmdloop()
64 break
65 except KeyboardInterrupt:
66 # Output a message - unless it's also interrupted
67 # pylint: disable=broad-except
68 try:
69 output('\nInterrupt\n')
70 except Exception:
71 pass
72 # pylint: enable=broad-except
73
74 def emptyline(self):
75 "Don't repeat last command when you hit return."
76 pass
77
78 def getLocals(self):
79 "Local variable bindings for py command"
80 self.locals.update(self.mn)
81 return self.locals
82
83 helpStr = (
84 'Supported commands are as follows:\n'
85 ' starrynet> help\n'
86 ' starrynet> create_nodes\n'
87 ' starrynet> create_links\n'
88 ' starrynet> run_routing_deamon\n'
89 ' starrynet> get_distance 1 2 10\n'
90 ' // It means getting the distance of two node (#1 and #2) at #10 second.\n'
91 ' starrynet> get_neighbors 5 16\n'
92 ' // It means getting the neighbor node indexes of node #5 at #16 second.\n'
93 ' starrynet> get_GSes 7 20\n'
94 ' // It means getting the connected GS node indexes of node #6 at #20 second.\n'
95 ' starrynet> get_position 7 23 \n'

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected