diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-02-03 19:12:54 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-02-03 19:18:31 +0100 |
commit | e7cafd34cc79df759f2ad9a13a7dc6f84e923f0b (patch) | |
tree | 18717cd66d47dcd722ad493f88fad525f6e982af | |
parent | 985c711e49d9503e52964766fceda78802aae656 (diff) | |
download | qutebrowser-e7cafd34cc79df759f2ad9a13a7dc6f84e923f0b.tar.gz qutebrowser-e7cafd34cc79df759f2ad9a13a7dc6f84e923f0b.zip |
Move json args loading to function
Needed to write tests.
-rw-r--r-- | qutebrowser/qutebrowser.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index 038421e98..fe8d824ec 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -183,17 +183,23 @@ def debug_flag_error(flag): .format(', '.join(valid_flags))) +def _unpack_json_args(args): + """Restore arguments from --json-args after a restart. + + When restarting, we serialize the argparse namespace into json, and + construct a "fake" argparse.Namespace here based on the data loaded + from json. + """ + data = json.loads(args.json_args) + return argparse.Namespace(**data) + + def main(): parser = get_argparser() argv = sys.argv[1:] args = parser.parse_args(argv) if args.json_args is not None: - # Restoring after a restart. - # When restarting, we serialize the argparse namespace into json, and - # construct a "fake" argparse.Namespace here based on the data loaded - # from json. - data = json.loads(args.json_args) - args = argparse.Namespace(**data) + args = _unpack_json_args(args) earlyinit.early_init(args) # We do this imports late as earlyinit needs to be run first (because of # version checking and other early initialization) |