1 import readline, textwrap
3 from rlcompleter import Completer
4 from lcfg2.config import ConfigEnvironment
5 from .common import ShconfigException, get_config_name
6 from .commands import Commands
8 class ConfigNameCompleter(Completer):
9 def __init__(self, env: ConfigEnvironment):
10 super().__init__(None)
14 get_config_name(x._name)
18 def complete(self, text, state):
20 text = text if text else ""
22 x for x in self.__config_set if x.startswith(text)]
24 return None if not self.__options else self.__options[state]
27 def next_input(cmds: Commands):
28 line = input("shconfig> ")
33 parts = line.split(' ')
34 name, args = parts[0], parts[1:]
36 if name in ['q', 'exit']:
40 raise KeyboardInterrupt()
42 if name.startswith("CONFIG_"):
43 cmds.call("opt", name)
46 cmds.call(name, *args)
49 def shconfig(env: ConfigEnvironment):
55 Lunaix Interactive Configurator (shconfig)
57 Type "help" to see all commands avaliables
58 Type "q" or "exit" to confirm and exit
59 Type "q!" or use ^C to discard and abort
65 cmpleter = ConfigNameCompleter(env)
66 readline.parse_and_bind('tab: complete')
67 readline.set_completer(cmpleter.complete)
71 if not next_input(cmds):
73 except ShconfigException as e:
76 except KeyboardInterrupt as e:
78 except Exception as e: