-
Notifications
You must be signed in to change notification settings - Fork 15
Extending a command
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 python
import sys
def print_definitions():
print("Extension for environment adding environment restart|")
print("[[environment]]|\"\"")
print(" restart|\"Restarts environemnt\" end ")
print("end")
def write(msg):
sys.stdout.write(msg+"\n")
sys.stdout.flush()
def wait_for_command():
while True:
line = sys.stdin.readline().strip("\n")
if line == "end-of-command":
break
def run_command(run_location, global_profile, local_profile, args):
# Run shutdown command to kill the environment and then starting it up again
write("shutting down..")
write("command|shutdown")
wait_for_command()
write("starting up...")
write("command|environment start")
if __name__ == "__main__":
args = sys.argv
if len(args) > 1 and args[2] == 'get-command-definitions':
print_definitions()
else:
run_command(args[1], args[2], args[3], args[4:])