]>
git.ipfire.org Git - nitsi.git/blob - src/nitsi/cmd.py
d50de6972151af737c3600468b95fd10075b4b84
4 def __init__(self
, prompt
="", help={}, intro
= ""):
5 self
.prompt
= "nitsi: "
6 self
.help_min
= {"help": "Shows this help message", "?": "Same as 'help'"}
17 def print_intro(self
, intro
=""):
20 self
.print_to_cmd(intro
)
22 def print_to_cmd(self
, string
):
23 print(string
, end
="\n")
25 def read_from_cmd(self
, prompt
=""):
30 def get_input(self
, valid_commands
=[], help={}):
31 valid_commands
= valid_commands
+ [ "?", "help" ]
35 input = self
.read_from_cmd()
36 if input not in valid_commands
:
37 self
.print_to_cmd("{} is not valid command.".format(input))
41 if input == "help" or input == "?":
42 self
.print_help(help=help)
45 # if we get here we get a valid input
50 def print_help(self
, help={}):
54 # Update help with help_min
55 tmp_help
= self
.help_min
60 self
.print_to_cmd("{}: {}".format(key
, help[key
]))