diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index 99e977d45..20dd0b6ad 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +import os import re import configargparse import argparse @@ -311,7 +312,7 @@ def common_options(parser): help="Don't start a proxy server." ) group.add_argument( - "-p", + "-p", "--port", action="store", type=int, dest="port", default=8080, help="Proxy service port." ) @@ -520,7 +521,16 @@ def mitmproxy(): # platforms. from .console import palettes - parser = configargparse.ArgumentParser(usage="%(prog)s [options]") + parser = configargparse.ArgumentParser( + usage="%(prog)s [options]", + args_for_setting_config_path = ["--conf"], + default_config_files = [ + os.path.join(config.CA_DIR, "common.conf"), + os.path.join(config.CA_DIR, "mitmproxy.conf") + ], + add_config_file_help = True, + add_env_var_help = True + ) parser.add_argument( '--version', action='version', @@ -551,7 +561,16 @@ def mitmproxy(): def mitmdump(): - parser = configargparse.ArgumentParser(usage="%(prog)s [options] [filter]") + parser = configargparse.ArgumentParser( + usage="%(prog)s [options] [filter]", + args_for_setting_config_path = ["--conf"], + default_config_files = [ + os.path.join(config.CA_DIR, "common.conf"), + os.path.join(config.CA_DIR, "mitmdump.conf") + ], + add_config_file_help = True, + add_env_var_help = True + ) parser.add_argument( '--version', @@ -577,7 +596,16 @@ def mitmdump(): def mitmweb(): - parser = configargparse.ArgumentParser(usage="%(prog)s [options]") + parser = configargparse.ArgumentParser( + usage="%(prog)s [options]", + args_for_setting_config_path = ["--conf"], + default_config_files = [ + os.path.join(config.CA_DIR, "common.conf"), + os.path.join(config.CA_DIR, "mitmweb.conf") + ], + add_config_file_help = True, + add_env_var_help = True + ) parser.add_argument( '--version', action='version', diff --git a/test/test_cmdline.py b/test/test_cmdline.py index 12e8aa897..476fc6206 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -1,7 +1,6 @@ import argparse from libmproxy import cmdline import tutils -import os.path def test_parse_replace_hook(): @@ -51,6 +50,7 @@ def test_parse_setheaders(): x = cmdline.parse_setheader("/foo/bar/voing") assert x == ("foo", "bar", "voing") + def test_common(): parser = argparse.ArgumentParser() cmdline.common_options(parser) @@ -108,3 +108,19 @@ def test_common(): assert len(v) == 1 assert v[0][2].strip() == "replacecontents" + +def test_mitmproxy(): + ap = cmdline.mitmproxy() + assert ap + + +def test_mitmdump(): + ap = cmdline.mitmdump() + assert ap + + +def test_mitmweb(): + ap = cmdline.mitmweb() + assert ap + +