in skywalking/bootstrap/cli/sw_python.py [0:0]
def start() -> None:
""" Entry point of CLI """
parser = argparse.ArgumentParser(description='SkyWalking Python Agent CLI',
epilog='Append your command, with SkyWalking agent attached for you automatically',
allow_abbrev=False)
parser.add_argument('-d', '--debug', help='Print CLI debug logs to stdout', action='store_true')
base_subparser = argparse.ArgumentParser(add_help=False)
subparsers = parser.add_subparsers(dest='option', required=True, help='CLI options, now only supports `run`, for '
'help please type `sw-python -h` or refer '
'to the CLI documentation')
run_parser = subparsers.add_parser('run', parents=[base_subparser])
# TODO support parsing optional sw_config.toml
# config_parser = subparsers.add_parser("config", parents=[base_subparser])
# parser.add_argument('-config', nargs='?', type=argparse.FileType('r'),
# help='Optionally takes a sw_python.toml config file')
run_parser.add_argument('-p', '--prefork', help='[Experimental] This flag turns on auto detection of '
'uwsgi and gunicorn, '
'then automatically starts the Python agent in each worker process.'
"(TL;DR: You don't need to add manual "
'@postfork hook to your app anymore)',
action='store_true')
# The command arg compress all remaining args into itself
# This must be the last arg
run_parser.add_argument('command', help='Your original commands e.g. gunicorn app.wsgi',
nargs=argparse.REMAINDER, metavar='command')
# To handle cases with flags and positional args in user commands
args = parser.parse_args() # type: argparse.Namespace
cli_logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
cli_logger.debug(f'Args received {args}')
if not args.command:
cli_logger.error('Command is not provided, please type `sw-python -h` for the list of command line arguments')
return
try:
dispatch(args)
except SWRunnerFailure:
cli_logger.exception(f"Failed to run the given user application command `{' '.join(args.command)}`, "
f'please make sure given command is valid.')
return