2021-11-30 09:12:51 +01:00
|
|
|
import argparse
|
2022-02-01 10:14:24 +01:00
|
|
|
from typing import Optional
|
2021-11-30 09:12:51 +01:00
|
|
|
|
|
|
|
from httpie.context import Environment
|
|
|
|
from httpie.status import ExitStatus
|
|
|
|
from httpie.manager.cli import missing_subcommand, parser
|
2022-02-01 10:14:24 +01:00
|
|
|
from httpie.manager.tasks import CLI_TASKS
|
2021-11-30 09:12:51 +01:00
|
|
|
|
|
|
|
MSG_COMMAND_CONFUSION = '''\
|
|
|
|
This command is only for managing HTTPie plugins.
|
|
|
|
To send a request, please use the http/https commands:
|
|
|
|
|
|
|
|
$ http {args}
|
|
|
|
|
|
|
|
$ https {args}
|
|
|
|
'''
|
|
|
|
|
|
|
|
# noinspection PyStringFormat
|
|
|
|
MSG_NAKED_INVOCATION = f'''\
|
|
|
|
{missing_subcommand()}
|
|
|
|
|
|
|
|
{MSG_COMMAND_CONFUSION}
|
|
|
|
'''.rstrip("\n").format(args='POST pie.dev/post hello=world')
|
|
|
|
|
|
|
|
|
2022-02-01 10:14:24 +01:00
|
|
|
def dispatch_cli_task(env: Environment, action: Optional[str], args: argparse.Namespace) -> ExitStatus:
|
|
|
|
if action is None:
|
|
|
|
parser.error(missing_subcommand('cli'))
|
|
|
|
|
|
|
|
return CLI_TASKS[action](env, args)
|
|
|
|
|
|
|
|
|
2021-11-30 09:12:51 +01:00
|
|
|
def program(args: argparse.Namespace, env: Environment) -> ExitStatus:
|
|
|
|
if args.action is None:
|
|
|
|
parser.error(MSG_NAKED_INVOCATION)
|
|
|
|
|
|
|
|
if args.action == 'plugins':
|
2022-04-03 15:06:42 +02:00
|
|
|
return dispatch_cli_task(env, args.action, args)
|
2022-02-01 10:14:24 +01:00
|
|
|
elif args.action == 'cli':
|
|
|
|
return dispatch_cli_task(env, args.cli_action, args)
|
2021-11-30 09:12:51 +01:00
|
|
|
|
|
|
|
return ExitStatus.SUCCESS
|