def parseOptions(): """ Merge default options with incoming options and arguments and return them as a dictionary. """ # Default options to start with options = marvin.getConfig() # Read from config file if available options.update(mergeOptionsWithConfigFile(options, "marvin_config.json")) # Switch through all options, commandline options overwrites. try: opts, args = getopt.getopt(sys.argv[1:], "hv", [ "help", "version", "config=", "server=", "port=", "channel=", "nick=", "realname=", "ident=" ]) for opt, arg in opts: if opt in ("-h", "--help"): printUsage(0) elif opt in ("-v", "--version"): printVersion() elif opt in "--config": options = mergeOptionsWithConfigFile(options, arg) elif opt in "--server": options["server"] = arg elif opt in "--port": options["port"] = arg elif opt in "--channel": options["channel"] = arg elif opt in "--nick": options["nick"] = arg elif opt in "--realname": options["realname"] = arg elif opt in "--ident": options["ident"] = arg else: raise Exception("Unhandled option") if args: raise Exception("Too many arguments, unknown argument.") except Exception as err: print(err) print(MSG_USAGE_SHORT) sys.exit(1) res = json.dumps(options, sort_keys=True, indent=4, separators=(',', ': ')) print("Configuration updated after cli options:\n{config}".format( config=res)) return options
def parseOptions(): """ Merge default options with incoming options and arguments and return them as a dictionary. """ # Default options to start with options = marvin.getConfig() # Read from config file if available options.update(mergeOptionsWithConfigFile(options, "marvin_config.json")) # Switch through all options, commandline options overwrites. try: opts, args = getopt.getopt(sys.argv[1:], "hv", [ "help", "version", "config=", "server=", "port=", "channel=", "nick=", "realname=", "ident=" ]) for opt, arg in opts: if opt in ("-h", "--help"): printUsage(0) elif opt in ("-v", "--version"): printVersion() elif opt in "--config": options = mergeOptionsWithConfigFile(options, arg) elif opt in "--server": options["server"] = arg elif opt in "--port": options["port"] = arg elif opt in "--channel": options["channel"] = arg elif opt in "--nick": options["nick"] = arg elif opt in "--realname": options["realname"] = arg elif opt in "--ident": options["ident"] = arg else: assert False, "Unhandled option" if args: assert False, "Too many arguments, unknown argument." except Exception as err: print(err) print(MSG_USAGE_SHORT) sys.exit(1) res = json.dumps(options, sort_keys=True, indent=4, separators=(',', ': ')) print("Configuration updated after cli options:\n{config}".format(config=res)) return options