From 0d29804ab852893e4e41c415de1ce3cc08ffcfae Mon Sep 17 00:00:00 2001 From: Henrique Date: Mon, 25 Nov 2019 08:56:44 -0500 Subject: [PATCH] Moved confdir check logic into the addon --- mitmproxy/addons/command_history.py | 6 +++++- mitmproxy/tools/_main.py | 14 ++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/mitmproxy/addons/command_history.py b/mitmproxy/addons/command_history.py index 3df2fe5d6..c66af2be4 100644 --- a/mitmproxy/addons/command_history.py +++ b/mitmproxy/addons/command_history.py @@ -14,7 +14,11 @@ class CommandHistory: self.current_index: int = -1 self.filter_str: str = '' - _command_history_path = os.path.join(os.path.expanduser(ctx.options.confdir), 'command_history') + _command_history_dir = os.path.expanduser(ctx.options.confdir) + if not os.path.exists(_command_history_dir): + os.makedirs(_command_history_dir) + + _command_history_path = os.path.join(_command_history_dir, 'command_history') _history_lines: typing.List[str] = [] if os.path.exists(_command_history_path): _history_lines = open(_command_history_path, 'r').readlines() diff --git a/mitmproxy/tools/_main.py b/mitmproxy/tools/_main.py index 3e6933b96..77f8e6759 100644 --- a/mitmproxy/tools/_main.py +++ b/mitmproxy/tools/_main.py @@ -69,6 +69,7 @@ def run( debug.register_info_dumpers() opts = options.Options() + master = master_cls(opts) parser = make_parser(opts) try: @@ -77,24 +78,13 @@ def run( arg_check.check() sys.exit(1) - try: - opts.set(*args.setoptions, defer=True) - opts.confdir = os.path.expanduser(opts.confdir) - if not os.path.isdir(opts.confdir): - os.makedirs(opts.confdir) - - except exceptions.OptionsError as e: - print("%s: %s" % (sys.argv[0], e), file=sys.stderr) - sys.exit(1) - - master = master_cls(opts) - # To make migration from 2.x to 3.0 bearable. if "-R" in sys.argv and sys.argv[sys.argv.index("-R") + 1].startswith("http"): print("-R is used for specifying replacements.\n" "To use mitmproxy in reverse mode please use --mode reverse:SPEC instead") try: + opts.set(*args.setoptions, defer=True) optmanager.load_paths( opts, os.path.join(opts.confdir, "config.yaml"),