Skip to main content

Simple tool to parse shell arguments using eval

Project description

ShellArgParser

A simple python tool to parse any arg / kwarg arguments in a manner that is easy to parse for the linux shell.

I don't understand

For example:

uvx ShellArgParser@latest --test=something -a -b -no-c

Will print this text:

ARGS_A=1
ARGS_B=1
ARGS_C=0
ARGS_TEST="something"

So running this:

eval $(uvx ShellArgParser@latest --test=something -a -b -no-c)

Will parse the args and kwargs as shell environment variables, handy for use in the shell:

echo $ARGS_TEST  # outputs 'something'

But why would you make this?

Handling user arguments are a major annoyance for me in shell, and in python using fire makes it a breeze, so it's is a great way to avoid reinventing the wheel. Hence, when writing a small shell script, using a python cli tool oneliner makes is a real time saver for me.

Notes:

  • -something is parsed as ARGS_SOMETHING=1
  • -no-something is parsed as ARGS_SOMETHING=0
  • -no_something is parsed as ARGS_SOMETHING=0
  • Any None python value is parsed as 0
  • A prototype 'pure shell' version of this script can be found in ./ShellArgParser.sh

Getting started

  • From pypi:
    • As a uv tool: uvx ShellArgParser@latest --help
    • Via uv: uv pip install ShellArgParser
    • Via pip: pip install ShellArgParser
  • From github:
    • Clone this repo then pip install .

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

shellargparser-0.2.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ShellArgParser-0.2.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file shellargparser-0.2.1.tar.gz.

File metadata

  • Download URL: shellargparser-0.2.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.20

File hashes

Hashes for shellargparser-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ed4c56ac5b384872a9e4f627a24244e91421b32a6cc500a98e5bb132956d0fff
MD5 4ccd4fa27931f6ffdd0c3cc5cbb05bb4
BLAKE2b-256 49fa47e5957eaca6af009df714780dc45f5a5c62f54ef4ddbce13c67d70368d9

See more details on using hashes here.

File details

Details for the file ShellArgParser-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ShellArgParser-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.20

File hashes

Hashes for ShellArgParser-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d439438cd8d262689536c42b5ac88747e72e2f73cbe3dd07b7a895a36e9376c9
MD5 55c4189e384c26cc9fef3a0cb1508ee8
BLAKE2b-256 e213220877367746b5f7eaed17470ab1290e226f744f599bfd1155633a10718f

See more details on using hashes here.

Supported by

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