Code Repositories xandikos / 5d3c01f
Use argparse rather than optparse. Jelmer Vernooń≥ 2 years ago
1 changed file(s) with 23 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
873873
874874
875875 def main(argv):
876 import optparse
876 import argparse
877877 import sys
878878 from xandikos import __version__
879 parser = optparse.OptionParser(version='.'.join(map(str, __version__)))
880 parser.usage = "%prog -d ROOT-DIR [OPTIONS]"
881
882 access_group = optparse.OptionGroup(parser, "Access Options")
883 access_group.add_option(
879 parser = argparse.ArgumentParser(
880 usage="%(prog)s -d ROOT-DIR [OPTIONS]",
881 prog=argv[0])
882
883 parser.add_argument(
884 '--version',
885 action='version',
886 version='%(prog)s ' + '.'.join(map(str, __version__)))
887
888 access_group = parser.add_argument_group(title="Access Options")
889 access_group.add_argument(
884890 "-l", "--listen_address", dest="listen_address", default="localhost",
885 help="Binding IP address. [%default]")
886 access_group.add_option(
891 help="Binding IP address. [%(default)s]")
892 access_group.add_argument(
887893 "-p", "--port", dest="port", type=int, default=8080,
888 help="Port to listen on. [%default]")
889 access_group.add_option(
894 help="Port to listen on. [%(default)s]")
895 access_group.add_argument(
890896 "--route-prefix", default="/", help=(
891897 "Path to Xandikos. "
892898 "(useful when Xandikos is behind a reverse proxy) "
893 "[%default]"))
894 parser.add_option_group(access_group)
895 parser.add_option(
899 "[%(default)s]"))
900 parser.add_argument(
896901 "-d", "--directory", dest="directory", default=None,
897902 help="Directory to serve from.")
898 parser.add_option(
903 parser.add_argument(
899904 "--current-user-principal", default="/user/",
900 help="Path to current user principal. [%default]")
901 parser.add_option(
905 help="Path to current user principal. [%(default)s]")
906 parser.add_argument(
902907 "--autocreate", action="store_true", dest="autocreate",
903908 help="Automatically create necessary directories.")
904 parser.add_option(
909 parser.add_argument(
905910 "--defaults", action="store_true", dest="defaults",
906911 help=("Create initial calendar and address book. "
907912 "Implies --autocreate."))
908 options, args = parser.parse_args(argv)
913 options = parser.parse_args(argv[1:])
909914
910915 if options.directory is None:
911916 parser.print_usage()