From 713856d15a7b33af3a0ea5fc1badc0069c59977e Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 11 Apr 2023 11:27:34 +0200 Subject: [PATCH] commandline: Handle missing config or credentials --- osc/commandline.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index f0c2b367dc..c872a6b2d3 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -392,17 +392,33 @@ def post_parse_args(self, args): # let's leave setting the right value to conf.get_config() pass - conf.get_config( - override_apiurl=args.apiurl, - override_conffile=args.conffile, - override_debug=args.debug, - override_http_debug=args.http_debug, - override_http_full_debug=args.http_full_debug, - override_no_keyring=args.no_keyring, - override_post_mortem=args.post_mortem, - override_traceback=args.traceback, - override_verbose=args.verbose, - ) + try: + conf.get_config( + override_apiurl=args.apiurl, + override_conffile=args.conffile, + override_debug=args.debug, + override_http_debug=args.http_debug, + override_http_full_debug=args.http_full_debug, + override_no_keyring=args.no_keyring, + override_post_mortem=args.post_mortem, + override_traceback=args.traceback, + override_verbose=args.verbose, + ) + except oscerr.NoConfigfile as e: + print(e.msg, file=sys.stderr) + print(f"Creating osc configuration file {e.file} ...", file=sys.stderr) + conf.interactive_config_setup(e.file, args.apiurl) + print("done", file=sys.stderr) + self.post_parse_args(args) + except oscerr.ConfigMissingApiurl as e: + print(e.msg, file=sys.stderr) + conf.interactive_config_setup(e.file, e.url, initial=False) + self.post_parse_args(args) + except oscerr.ConfigMissingCredentialsError as e: + print(e.msg, file=sys.stderr) + print("Please enter new credentials.", file=sys.stderr) + conf.interactive_config_setup(e.file, e.url, initial=False) + self.post_parse_args(args) # write config values back to args # this is crucial mainly for apiurl to resolve an alias to full url