-
Notifications
You must be signed in to change notification settings - Fork 15
Overriding a sub command
Just like overriding 1st position command overriding sub commands without having to touch the original package can be useful. So the oi environment details [KEY] command requires that KEY is specified. Let's say that we wanted to have KEY default to current configuration point. Again we will use the double square brace to specify existing commands/sub commands in where we want to override our sub command. Details the sub command we want to override we annotate as a normal lowercase sub command. We also add the optional argument to KEY for good measure. After preparing the path we use the command-original| prefixed command to run the details command we just replaced.
This sample is in python as I enjoy using python. You can use any language you want
#!/usr/bin/env python
import os, sys
def print_definitions():
print("Overrides environment details. Uses current when KEY is not specified|")
print("[[environment]]|\"\"")
print(" details|\"Displays details about a running environment\"")
print(" [KEY]|\"The environment key path. Default current\" end ")
print(" end ")
print("end")
def run_command(run_location, global_profile, local_profile, args):
key = os.getcwd()
# First argument is the name of the sub command "details" so path is second
if len(args) > 1:
key = args[1]
# Run the command that was overridden by this script
print("command-original|environment details \""+key+"\"")
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:])