MCPcopy
hub / github.com/httpie/cli / raw_main

Function raw_main

httpie/core.py:32–143  ·  view source on GitHub ↗
(
    parser: argparse.ArgumentParser,
    main_program: Callable[[argparse.Namespace, Environment], ExitStatus],
    args: List[Union[str, bytes]] = sys.argv,
    env: Environment = Environment(),
    use_default_options: bool = True,
)

Source from the content-addressed store, hash-verified

30
31# noinspection PyDefaultArgument
32def raw_main(
33 parser: argparse.ArgumentParser,
34 main_program: Callable[[argparse.Namespace, Environment], ExitStatus],
35 args: List[Union[str, bytes]] = sys.argv,
36 env: Environment = Environment(),
37 use_default_options: bool = True,
38) -> ExitStatus:
39 program_name, *args = args
40 env.program_name = os.path.basename(program_name)
41 args = decode_raw_args(args, env.stdin_encoding)
42
43 if is_daemon_mode(args):
44 return run_daemon_task(env, args)
45
46 plugin_manager.load_installed_plugins(env.config.plugins_dir)
47
48 if use_default_options and env.config.default_options:
49 args = env.config.default_options + args
50
51 include_debug_info = '--debug' in args
52 include_traceback = include_debug_info or '--traceback' in args
53
54 def handle_generic_error(e, annotation=None):
55 msg = str(e)
56 if hasattr(e, 'request'):
57 request = e.request
58 if hasattr(request, 'url'):
59 msg = (
60 f'{msg} while doing a {request.method}'
61 f' request to URL: {request.url}'
62 )
63 if annotation:
64 msg += annotation
65 env.log_error(f'{type(e).__name__}: {msg}')
66 if include_traceback:
67 raise
68
69 if include_debug_info:
70 print_debug_info(env)
71 if args == ['--debug']:
72 return ExitStatus.SUCCESS
73
74 exit_status = ExitStatus.SUCCESS
75
76 try:
77 parsed_args = parser.parse_args(
78 args=args,
79 env=env,
80 )
81 except NestedJSONSyntaxError as exc:
82 env.stderr.write(str(exc) + "\n")
83 if include_traceback:
84 raise
85 exit_status = ExitStatus.ERROR
86 except KeyboardInterrupt:
87 env.stderr.write('\n')
88 if include_traceback:
89 raise

Callers 2

mainFunction · 0.90
mainFunction · 0.85

Calls 12

decode_raw_argsFunction · 0.85
is_daemon_modeFunction · 0.85
run_daemon_taskFunction · 0.85
print_debug_infoFunction · 0.85
check_updatesFunction · 0.85
unwrap_contextFunction · 0.85
handle_generic_errorFunction · 0.85
log_errorMethod · 0.80
EnvironmentClass · 0.70
parse_argsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected