def parse(args): """ Parse the CLI options and call the correct functions based on them. """ known_commands = ("version", "versions", "install", "help", "use", "remove") if len(args) == 0: shared.help_func(__helpstr__) elif args[0] == "help" or args[0] == "-h" or args[0] == "--help": shared.help_func(__helpstr__) elif args[0] == "-v" or args[0] == "--version": sys.stdout.write("nodevers %s\n" % nodevers.__version__) elif args[0] not in known_commands: sys.stderr.write("Error: unrecognized command: '%s'\n" % args[0]) sys.exit(-1) if args[0] == "version": version.parse(args[1:]) elif args[0] == "versions": versions.parse(args[1:]) elif args[0] == "install": install.parse(args[1:]) elif args[0] == "use": use.parse(args[1:]) elif args[0] == "remove": remove.parse(args[1:])
def parse(args): """ Parse the arguments and call the correct functions based on them. """ if len(args) == 0: for ver in get_versions_list(): sys.stdout.write("%s\n" % ver) else: try: optlist, arglist = getopt.getopt(args, "h", ["help"]) except getopt.error: err = sys.exc_info()[1] sys.stderr.write("Error: %s\n" % str(err)) sys.exit(-1) for option, value in optlist: if option in ("-h", "--help"): shared.help_func(__helpstr__)
def parse(args): """ Parse the arguments and call the correct functions based on them. """ if len(args) == 0: shared.help_func(__helpstr__) else: try: optlist, arglist = getopt.getopt(args, "h", ["help"]) except getopt.error: err = sys.exc_info()[1] sys.stderr.write("Error: %s.\n" % str(err)) sys.exit(-1) for option, value in optlist: if option in ("-h", "--help"): shared.help_func(__helpstr__) if shared.version_exists(args[0]): remove(args[0]) else: sys.stdout.write("Error: there is no such version installed\n")
def parse(args): """ Parse the CLI options and call the correct functions based on them. """ if len(args) == 0 or args[0] in ("-h", "--help"): shared.help_func(__helpstr__) else: build_args = "" try: optlist, arglist = getopt.getopt(args[1:], "h", ["help", "buildargs="]) except getopt.error: err = sys.exc_info()[1] sys.stderr.write("Error: %s\n" % str(err)) sys.exit(-1) for option, value in optlist: if option in ("-h", "--help"): shared.help_func(__helpstr__) elif option in ("--buildargs"): build_args = value install(args[0], build_args)
def parse(args): """ Parse the arguments and call the correct functions based on them. """ if len(args) == 0 or args[0] in ("-h", "--help"): shared.help_func(__helpstr__) else: try: optlist, arglist = getopt.getopt(args[1:], "h", ["help"]) except getopt.error: err = sys.exc_info()[1] sys.stderr.write("Error: %s\n" % str(err)) sys.exit(-1) for option, value in optlist: if option in ("-h", "--help"): shared.help_func(__helpstr__) try: shared.link_to(args[0]) except shared.NoSuchVersionError: err = sys.exc_info()[1] sys.stdout.write("Error: %s\n" % str(err))