You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Svein Arne Ackenhausen edited this page May 10, 2014
·
2 revisions
To be able to extend a script without actually having to make changes to it directly we have the opportunity to add sub commands through new scripts. Let's say we want the oi environment command as is but we want to add an option to restart a running environment by adding a oi environment restart command. We do that by specifying the parts to override using double square braces. After adding this script we can see that the oi help environment command lists restart as a valid argument.
This sample is in python as I enjoy using python. You can use any language you want
#!/usr/bin/env pythonimportsysdefprint_definitions():
print("Extension for environment adding environment restart|")
print("[[environment]]|\"\"")
print(" restart|\"Restarts environemnt\" end ")
print("end")
defwrite(msg):
sys.stdout.write(msg+"\n")
sys.stdout.flush()
defwait_for_command():
whileTrue:
line=sys.stdin.readline().strip("\n")
ifline=="end-of-command":
breakdefrun_command(run_location, global_profile, local_profile, args):
# Run shutdown command to kill the environment and then starting it up againwrite("shutting down..")
write("command|shutdown")
wait_for_command()
write("starting up...")
write("command|environment start")
if__name__=="__main__":
args=sys.argviflen(args) >1andargs[2] =='get-command-definitions':
print_definitions()
else:
run_command(args[1], args[2], args[3], args[4:])