def cmdline(): parser = argparse.ArgumentParser() config.add_inifile_argument(parser) config.add_db_url_argument(parser) config.add_ca_arguments(parser) parser.add_argument( "--long", help="Generate a long lived cert(1 year)", action="store_true", ) parser.add_argument( "--list", help="List active requests, do nothing else", action="store_true", ) exclusives = parser.add_mutually_exclusive_group() exclusives.add_argument( "--sign", metavar="id", type=int, help="Sign the CSR with this id" ) exclusives.add_argument( "--reject", metavar="id", type=int, help="Reject the CSR with this id", ) cleanout = parser.add_mutually_exclusive_group() cleanout.add_argument( "--clean", metavar="id", type=int, help="Remove all older certificates for this CSR", ) cleanout.add_argument( "--wipe", metavar="id", type=int, help="Wipe all certificates for this CSR", ) bulk = parser.add_mutually_exclusive_group() bulk.add_argument( "--refresh", help="Sign all certificates that have a valid current signature.", action="store_true", ) bulk.add_argument( "--cleanall", help="Clean all older certificates.", action="store_true", ) args = parser.parse_args() # Didn't find a way to do this with argparse, but I didn't look too hard. return args
def test_no_ini_path(self): """no path in either argument or evironment, should raise ValueError""" parser = argparse.ArgumentParser() config.add_inifile_argument(parser, {}) with self.assertRaises(ValueError): parser.parse_args([])
def test_inifile_argument(self): """path as argument, no path in the environment""" my_ini = "/a/path/to/my_ini_file.ini" parser = argparse.ArgumentParser() config.add_inifile_argument(parser, {}) args = parser.parse_args([my_ini]) self.assertEqual(args.inifile, my_ini)
def cmdline(): parser = argparse.ArgumentParser() config.add_inifile_argument(parser) config.add_verbosity_argument(parser) config.add_ca_arguments(parser) args = parser.parse_args() return args
def test_inifile_env(self): """path in the environment, no path argument""" my_ini = "/a/path/to/my_ini_file.ini" env = {"CARAMEL_INI": my_ini} parser = argparse.ArgumentParser() config.add_inifile_argument(parser, env) args = parser.parse_args([]) self.assertEqual(args.inifile, my_ini)
def test_inifile_argument_env(self): """different paths as argument and in environment, argument takes priority""" my_ini = "/a/path/to/my_ini_file.ini" other_ini = "/a/path/to/other_ini_file.ini" env = {"CARAMEL_INI": other_ini} parser = argparse.ArgumentParser() config.add_inifile_argument(parser, env) args = parser.parse_args([my_ini]) self.assertEqual(args.inifile, my_ini)
def cmdline(): """Basically just parsing the arguments and returning them""" parser = argparse.ArgumentParser() config.add_inifile_argument(parser) config.add_db_url_argument(parser) config.add_verbosity_argument(parser) config.add_ca_arguments(parser) parser.add_argument("--delay", help="How long to sleep. (ms)") parser.add_argument("--valid", help="How many hours the certificate is valid for") args = parser.parse_args() return args