mirror of
https://github.com/httpie/cli.git
synced 2024-11-08 00:44:45 +01:00
c157948531
* Add `httpie cli plugins` in favor of the new cli namespace. * Separate each task to individual modules. * Move httpie.manager.plugins to httpie.manager.tasks.plugins Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import argparse
|
|
from typing import Optional
|
|
|
|
from httpie.context import Environment
|
|
from httpie.status import ExitStatus
|
|
from httpie.manager.cli import missing_subcommand, parser
|
|
from httpie.manager.tasks import CLI_TASKS
|
|
|
|
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')
|
|
|
|
|
|
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)
|
|
|
|
|
|
def program(args: argparse.Namespace, env: Environment) -> ExitStatus:
|
|
if args.action is None:
|
|
parser.error(MSG_NAKED_INVOCATION)
|
|
|
|
if args.action == 'plugins':
|
|
return dispatch_cli_task(env, args.action, args)
|
|
elif args.action == 'cli':
|
|
return dispatch_cli_task(env, args.cli_action, args)
|
|
|
|
return ExitStatus.SUCCESS
|