Skip to main content

Library of xonsh subprocess specification modifiers.

Project description

Library of xonsh subprocess specification modifiers.

If you like the idea click ⭐ on the repo and tweet.

Installation

To install use pip:

xpip install xontrib-spec-mod
xpip install 'xontrib-spec-mod[dict,yaml]'  # Additional modifiers.

Load:

xontrib load spec_mod

Usage

Transform output to object

Modifiers:

  • @lines - return list of lines.
  • @json - json to Python dict.
  • @dict - dict-like object (json, JavaScript object, Python dict) to Python dict. Install extra support via xpip install 'xontrib-spec-mod[dict]'.
  • @path - string to pathlib.Path.
  • @yaml - YAML to Python dict. Install xpip install 'xontrib-spec-mod[yaml]'.

Examples:

$(@lines ls /)
# ['/bin', '/etc', '/home']

$(@json echo '{"a":1}')  # Try with `curl` ;)
# dict({"a":1})

$(@path which xonsh)
# Path('/path/to/xonsh')

$(@path which xonsh).parent
# Path('/path/to')


aliases['ydig'] = '@yaml dig +yaml'  # Update `dig` via `brew install bind` to have `+yaml`.
y = $(ydig google.com)
y[0]['type']
# 'MESSAGE'

Error handling

Modifiers:

  • @noerr - set $RAISE_SUBPROC_ERROR=False for the command.

Examples:

$RAISE_SUBPROC_ERROR = True  # General environment.
if ![@noerr ls nononofile]:  # Do not raise exception in case of error.
    echo file 

Development

# install pre-commit plugins and activate the commit hook
pre-commit install
pre-commit autoupdate

Credits

This package was created with xontrib template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xontrib_spec_mod-0.0.2.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

xontrib_spec_mod-0.0.2-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page