Last active
April 26, 2019 00:01
-
-
Save flerpadoo/6394de9ae337d53aa3b7acf98192404d to your computer and use it in GitHub Desktop.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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