1
0
mirror of https://github.com/httpie/cli.git synced 2025-01-20 02:59:47 +02:00

Removed the management command.

It means that:

    httpie session list
    httpie session edit
    ...

are gone.

It has never been part of a stable release, and since it wasn't
a very useful feature, it's beeing removed now to avoid feature creep.
This commit is contained in:
Jakub Roztocil 2013-02-22 13:27:26 +01:00
parent 3043f24733
commit 5cc5b13555
4 changed files with 8 additions and 207 deletions

View File

@ -886,15 +886,14 @@ Session data are stored in JSON files in the directory
**Warning:** All session data, including credentials, cookie data, **Warning:** All session data, including credentials, cookie data,
and custom headers are stored in plain text. and custom headers are stored in plain text.
Another way to create or update a session is to use the `management tool`_ Session files can also be created or edited with a text editor.
and then edit the raw JSON manually:
.. code-block:: bash .. code-block:: bash
$ httpie session edit example.org user1 $ httpie session edit example.org user1
See also `Management Tool`_ and `Config`_. See also `Config`_.
====== ======
@ -938,28 +937,6 @@ The config directory location can be changed by setting the
``HTTPIE_CONFIG_DIR`` environment variable. ``HTTPIE_CONFIG_DIR`` environment variable.
===============
Management Tool
===============
The main executable HTTPie comes with is ``http``, which is used for making
HTTP requests. The ``httpie`` command, on the other hand, is a utility for
managing your configuration. The currently supported actions are:
``httpie session list [hostname]``:
List all existing sessions, or a host's sessions only.
``httpie session edit hostname session-name``:
Create and/or edit a session file in ``$EDITOR``.
``httpie session show hostname session-name``:
Print a session data to the console.
``httpie session delete hostname [session-name]``
Delete all host's sessions or a specific one by name.
========= =========
Scripting Scripting
========= =========
@ -1103,7 +1080,6 @@ Changelog
* `0.4.0-alpha`_ * `0.4.0-alpha`_
* Python 3.3 compatibility. * Python 3.3 compatibility.
* Requests v1.0.4 compatibility. * Requests v1.0.4 compatibility.
* Added ``httpie`` management command.
* Added support for credentials in URL. * Added support for credentials in URL.
* Added ``--no-option`` for every ``--option`` to be config-friendly. * Added ``--no-option`` for every ``--option`` to be config-friendly.
* Mutually exclusive arguments can be specified multiple times. The * Mutually exclusive arguments can be specified multiple times. The

View File

@ -10,14 +10,13 @@ from argparse import FileType, OPTIONAL, ZERO_OR_MORE, SUPPRESS
from . import __doc__ from . import __doc__
from . import __version__ from . import __version__
from .compat import is_windows from .compat import is_windows
from .sessions import DEFAULT_SESSIONS_DIR from .sessions import DEFAULT_SESSIONS_DIR, Session
from .manage import session_name_validator
from .output import AVAILABLE_STYLES, DEFAULT_STYLE from .output import AVAILABLE_STYLES, DEFAULT_STYLE
from .input import (Parser, AuthCredentialsArgType, KeyValueArgType, from .input import (Parser, AuthCredentialsArgType, KeyValueArgType,
SEP_PROXY, SEP_CREDENTIALS, SEP_GROUP_ITEMS, SEP_PROXY, SEP_CREDENTIALS, SEP_GROUP_ITEMS,
OUT_REQ_HEAD, OUT_REQ_BODY, OUT_RESP_HEAD, OUT_REQ_HEAD, OUT_REQ_BODY, OUT_RESP_HEAD,
OUT_RESP_BODY, OUTPUT_OPTIONS, OUT_RESP_BODY, OUTPUT_OPTIONS,
PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY) PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, RegexValidator)
def _(text): def _(text):
@ -224,7 +223,10 @@ sessions = parser.add_argument_group(title='Sessions')\
.add_mutually_exclusive_group(required=False) .add_mutually_exclusive_group(required=False)
sessions.add_argument( sessions.add_argument(
'--session', metavar='SESSION_NAME', type=session_name_validator, '--session', metavar='SESSION_NAME', type=RegexValidator(
Session.VALID_NAME_PATTERN,
'Session name contains invalid characters.'
),
help=_(''' help=_('''
Create, or reuse and update a session. Create, or reuse and update a session.
Within a session, custom headers, auth credential, as well as any Within a session, custom headers, auth credential, as well as any

View File

@ -1,109 +0,0 @@
"""
Provides the `httpie' management command.
Note that the main `http' command points to `httpie.__main__.main()`.
"""
import inspect
import argparse
import functools
from .input import RegexValidator
from .sessions import (Session, Host,
command_session_list,
command_session_edit,
command_session_show,
command_session_delete)
parser = argparse.ArgumentParser(
description='The HTTPie management command.'
)
subparsers = parser.add_subparsers()
#################################################################
# Session commands
#################################################################
hostname_validator = RegexValidator(
Host.VALID_NAME_PATTERN,
'Hostname contains invalid characters.'
)
session_name_validator = RegexValidator(
Session.VALID_NAME_PATTERN,
'Session name contains invalid characters.'
)
def make_command(func):
@functools.wraps(func)
def wrapper(parsed_args):
"""Convert parsed args to function kwargs."""
kwargs = dict((name, getattr(parsed_args, name, None))
for name in inspect.getargspec(func).args)
return func(**kwargs)
return wrapper
def add_hostname_arg(parser, *args, **kwargs):
parser.add_argument(
'hostname', metavar='HOSTNAME',
type=hostname_validator,
*args, **kwargs
)
def add_session_name_arg(parser, *args, **kwargs):
parser.add_argument(
'session_name', metavar='SESSION_NAME',
type=session_name_validator,
*args, **kwargs
)
session = subparsers.add_parser('session',
help='manipulate and inspect sessions').add_subparsers()
# List
session_list_parser = session.add_parser('list', help='list sessions')
session_list_parser.set_defaults(command=make_command(command_session_list))
add_hostname_arg(session_list_parser, nargs=argparse.OPTIONAL)
# Show
session_show_parser = session.add_parser('show', help='show a session')
session_show_parser.set_defaults(command=make_command(command_session_show))
add_hostname_arg(session_show_parser)
add_session_name_arg(session_show_parser)
# Edit
session_edit_parser = session.add_parser(
'edit', help='edit a session in $EDITOR')
session_edit_parser.set_defaults(command=make_command(command_session_edit))
add_hostname_arg(session_edit_parser)
add_session_name_arg(session_edit_parser)
# Delete
session_delete_parser = session.add_parser('delete', help='delete a session')
session_delete_parser.set_defaults(
command=make_command(command_session_delete))
add_hostname_arg(session_delete_parser)
add_session_name_arg(session_delete_parser, nargs=argparse.OPTIONAL,
help='The name of the session to be deleted.'
' If not specified, all of the host\'s')
#################################################################
# Main
#################################################################
def main():
args = parser.parse_args()
args.command(args)
if __name__ == '__main__':
main()

View File

@ -3,12 +3,9 @@
""" """
import re import re
import os import os
import sys
import glob import glob
import errno import errno
import codecs
import shutil import shutil
import subprocess
import requests import requests
from requests.cookies import RequestsCookieJar, create_cookie from requests.cookies import RequestsCookieJar, create_cookie
@ -16,7 +13,6 @@ from requests.auth import HTTPBasicAuth, HTTPDigestAuth
from .compat import urlsplit from .compat import urlsplit
from .config import BaseConfigDict, DEFAULT_CONFIG_DIR from .config import BaseConfigDict, DEFAULT_CONFIG_DIR
from .output import PygmentsProcessor
SESSIONS_DIR_NAME = 'sessions' SESSIONS_DIR_NAME = 'sessions'
@ -181,67 +177,3 @@ class Session(BaseConfigDict):
'username': cred.username, 'username': cred.username,
'password': cred.password, 'password': cred.password,
} }
##################################################################
# Session management commands
##################################################################
def command_session_list(hostname=None):
"""Print a list of all sessions or only
the ones from `args.host`, if provided.
"""
if hostname:
for session in Host(hostname):
print(session.verbose_name)
else:
for host in Host.all():
for session in host:
print(session.verbose_name)
def command_session_show(hostname, session_name):
"""Print JSON data for a session."""
session = Session(Host(hostname), session_name)
path = session.path
if not os.path.exists(path):
sys.stderr.write('Session does not exist: %s\n'
% session.verbose_name)
sys.exit(1)
with codecs.open(path, encoding='utf8') as f:
print(session.verbose_name + ':\n')
proc = PygmentsProcessor()
print(proc.process_body(f.read(), 'application/json', 'json'))
print('')
def command_session_delete(hostname, session_name=None):
"""Delete a session by host and name, or delete all the
host's session if name not provided.
"""
host = Host(hostname)
if not session_name:
host.delete()
session = Session(host, session_name)
session.delete()
def command_session_edit(hostname, session_name):
"""Open a session file in EDITOR."""
editor = os.environ.get('EDITOR', None)
if not editor:
sys.stderr.write(
'You need to configure the environment variable EDITOR.\n')
sys.exit(1)
session = Session(Host(hostname), session_name)
if session.is_new:
session.save()
command = editor.split()
command.append(session.path)
subprocess.call(command)