Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example as used in live code of an extremely simple and configurable command-line manager I wrote. I don't have the repo here, but I'll probably put it up soon once I can remember how the hell to use it. Found this while looking for examples in my own code. :p
activeCommands =[
['sleepmon',[
['start', 'startSystemSleepMonitor(); cd printMsg(\'System Sleep Monitor has been started\', 0, True)'],
['stop', 'global sleepMonitorKill; sleepMonitorKill = True'],
['status', "'sleepmon: active' if sleepMonitorKill else 'sleepmon: inactive'"]]
],
['connect',[
['global tm; tm = TunnelManager(); tm.initSSH()']]
]
]
def processUserInput(userInput, cmdLib):
userInput = userInput.split(' ')
for cmd in cmdLib:
if userInput[0] == cmd[0]:
for arg in cmd[1]:
if len(userInput) == 1:
print(arg[0])
return
if len(userInput) > 1:
if userInput[1] == arg[0]:
print(arg[1])
return
processUserInput("connect", activeCommands)
for cmd in activeCommands:
if userInput[0] == cmd[0]:
for arg in cmd[1]:
if userInput[1]:
if userInput[1] == arg[0]:
exec(arg[1])
return
if not userInput[1]:
exec(arg[0])
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.