def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, version="smart %s" % VERSION) parser.disable_interspersed_args() parser.add_option( "--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)") ) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option( "--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)") ) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option( "-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair"), ) opts, args = parser.parse_args() if args: opts.command = args[0] opts.argv = args[1:] else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell): parser.print_help() sys.exit(1) return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, skipunknown=True, add_help_option=False, version="smart %s" % VERSION) parser.add_option("--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)")) parser.add_option("--rootfs-dir", metavar=_("DIR"), help=_("rootfs directory")) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option("--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)")) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--quiet", action="store_true", help=_("use the quiet interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option("-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair")) opts, args = parser.parse_args() if args: opts.command = arg = args[0] opts.argv = args[1:] if arg and arg[0] == "-": if arg == "-h" or len(arg) > 2 and "--help".startswith(arg): parser.print_help() sys.exit(0) else: raise Error, _("no such option: %s") % arg else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell or opts.interface): parser.print_help() sys.exit(1) return opts
def parse_options(argv): parser = OptionParser(usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, version="smart %s" % VERSION) parser.disable_interspersed_args() parser.add_option("--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)")) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option("--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)")) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option("-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair")) opts, args = parser.parse_args() if args: opts.command = args[0] opts.argv = args[1:] else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell): parser.print_help() sys.exit(1) return opts
def parse_options(argv): parser = OptionParser( usage=USAGE, description=DESCRIPTION, examples=EXAMPLES, skipunknown=True, add_help_option=False, version="smart %s" % VERSION, ) parser.add_option( "--config-file", metavar=_("FILE"), help=_("configuration file " "(default is <data-dir>/config)") ) parser.add_option("--data-dir", metavar=_("DIR"), help=_("data directory (default is %s)") % DATADIR) parser.add_option( "--log-level", metavar=_("LEVEL"), help=_("set the log level to LEVEL (debug, info, " "warning, error)") ) parser.add_option("--gui", action="store_true", help=_("use the default graphic interface")) parser.add_option("--shell", action="store_true", help=_("use the default shell interface")) parser.add_option("--interface", metavar=_("NAME"), help=_("use the given interface")) parser.add_option("--ignore-locks", action="store_true", help=_("don't respect locking")) parser.add_option( "-o", "--option", action="append", default=[], metavar=_("OPT"), help=_("set the option given by a name=value pair"), ) opts, args = parser.parse_args() if args: opts.command = arg = args[0] opts.argv = args[1:] if arg and arg[0] == "-": if arg == "-h" or len(arg) > 2 and "--help".startswith(arg): parser.print_help() sys.exit(0) else: raise Error, _("no such option: %s") % arg else: opts.command = None opts.argv = [] if not (opts.command or opts.gui or opts.shell or opts.interface): parser.print_help() sys.exit(1) return opts