Skip to main content

Argument aliases/abbrevations for CLI programs (compatible with argparse/click/typer/...)

Project description

ArgAlias

Run tests and upload coverage codecov

Aliases for arguments in Python CLI utilities (supports argparse, Typer, Click, and similar tools).

This tool is for those who sometimes prefer to type p sh X instead of project show X.

You configure which canonical CLI arguments you expect, and what aliases are allowed (e.g. for the canonical argument "show" good aliases are "sh" and "get").

If a canonical name is configured with a prefix, aliases will be resolved only if they follow configured prefix from the first argument.

Simplify your CLI! Add ArgAlias to your argparse, Click, or Typer project in 10 minutes!

Installation

pip3 install argalias

How to use

When you add aliases, the first element is either a str (the canonical name to which the alias will be resolved to) or a List[str] containing prefixes with canonical name.

Each element in the prefix list can be either a simple string (a parameter), * (matches any value of parameter) or values separated by the | symbol.

from argalias import ArgAlias

aa = ArgAlias()

# The script expects "show" parameter anywhere, and it can be aliased as "sh", "s" or even "get"
aa.alias("show", "get", "sh", "s")

# The script expects "employee" as the first parameter, can be aliased as "emp" or "e" 
aa.alias(["employee"], "emp", "e")

# same for "project"
aa.alias(["project"], "proj", "p")

# The script expects "create" parameter after "employee" or "project". Can be aliased as "cr" or "c"
aa.alias(["employee|project", "create"], "cr", "c")

# The script expects "delete" as the second parameter after any parameter, can be aliased as "del" or "d"
aa.alias(["*", "delete"], "del", "d")
aa.parse()
# sys.argv now has all aliases resolved, e.g. "sh" resolved to "show"
print(sys.argv)

You can find examples using argparse, Click, and Typer in examples/.

Results:

p sh Something -> project show Something
project cr Mayhem -> project create Mayhem

These aliases will not be replaced:

sh emp John ("sh" resolved to "show" but "emp" not resolved: not a first argument)
zzz cr xxx ("cr" not resolved: not after employee or project)
aaa bbb del ("del" not resolved: prefix is "aaa", "bbb" - two elements, not matching "*")

Might be replaced incorrectly:

project create sh (You want to create a project named "sh", but "sh" will be replaced with "show" because the alias does not specify any prefix requirements.)

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

argalias-0.1.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

argalias-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file argalias-0.1.2.tar.gz.

File metadata

  • Download URL: argalias-0.1.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for argalias-0.1.2.tar.gz
Algorithm Hash digest
SHA256 168cc3b0d8caeb07ebde5a62c66ca114beeff9944750f5ce180b7b04f955a02a
MD5 d01b0db0a3a42ad588569454d75e86fc
BLAKE2b-256 d5621a60d5d814d4ae87a013388a48304de13dc52b2827290abb2cfebcf7c000

See more details on using hashes here.

File details

Details for the file argalias-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: argalias-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for argalias-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 849bd04ccdf66f042d95e3b78dbc789cff7a90cfe0b564416c76f6d191df39dc
MD5 3b5de76341a89534cf42c6e29b11d74c
BLAKE2b-256 2bb8b79ce79cd87c80fda036119d8d4bd02d193cb8f57449093e676ab302459f

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