Skip to main content

An argparse extension to easily manage post-processing of multiple parsed arguments

Project description

ArgCompile

Python Version License PyPI

Command-line parsing library

This module proposes to extend argparse command-line parsing library objects in order to promote devices to easily apply post-parsing processing over supplied arguments.

The package contains three public design classes, some useful implementations of them and other auxiliary classes. The most significant ones are described bellow:

ArgumentCompiler

The main entry point for command-line parsing, extended to process new-design group usage test, attribute formation and Namespace compilation. Following its superclass, ArgumentParser, it's filled by Actions that defines as command line should be parsed. By extension, add_attribute() method process the inclusion of complex ActionsContainer named accordingly.

  • FileSelector: A multiple file opener that filters selection based on path, filename(s) and extension(s)
  • FileComputer: A FileSelector specialization that also defines an output target
  • YamlCompuler: A FileComputer based class that restricts yaml and yml file extensions, already loading its content to a dictionary

Attribute

An ActionsContainer specialization to manage parsing of multiple arguments into an unique Namespace attribute. Implementations of it can be made in order to define how a Namespace attribute should be constructed based on the several target arguments parsed.

  • Target: Defines a reference collection of the main parsed object
  • Extension: Designed to accumulate a list of extensions, allowing defining special arguments for desired options
  • Output: Defines title and opening-mode of a writing file

CustomGroup

A group-type class that allows post parsing usage tests to be executed. This design enables the implementation of custom rules in Action groups.

  • RequiredGroup: A simple group that checks the presence of its arguments to require at least one has been provided
  • DependentGroup: Restricts the use of its arguments based on presence of its dependence list

Example

The following code is a Python program that prints out the file list of a target path

# ls.py
from argcompile import FileSelector

class Ls(FileSelector):
	def __call__(self, namespace):
		for file in namespace.file:
			print(file.name)

compiler = Ls(
	path={
		'*': ['path'],
		'nargs': 1
	}
)
compiler.parse_args()

It can be run at the command line and provides useful help messages:

$ python3 ls.py -h
usage: ls.py [-h] [--all] [-e ext [ext ...]]
           path [filename [filename ...]]

positional arguments:
  path                  define path to look up files from
  filename              define chosen filenames

optional arguments:
  -h, --help            show this help message and exit
  --all                 select all filenames
  -e ext [ext ...],     restrict files extension(s)

When run with the appropriate arguments, it does the job:

$ python3 ls.py . --all
./.gitignore
./DESCRIPTION.md
./LICENSE
./makefile
./MANIFEST.in
./README.md
./setup.cfg
./setup.py

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

argcompile-0.0.9.zip (13.9 kB view details)

Uploaded Source

Built Distribution

argcompile-0.0.9-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file argcompile-0.0.9.zip.

File metadata

  • Download URL: argcompile-0.0.9.zip
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for argcompile-0.0.9.zip
Algorithm Hash digest
SHA256 afa0b3fa7b0e1a0d7aa28381d080d81ce8dfa1ee13fc2508a34832ec33a9c98a
MD5 7a21199bef47df0bb35efe4bc5e041bb
BLAKE2b-256 d9a830adc550b05ac16afc4863cf7a8cddfc559fbb8e15ead69867fdeca25aeb

See more details on using hashes here.

File details

Details for the file argcompile-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: argcompile-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for argcompile-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 25b42bcce94d8a87217483f963b7b0495eef42f052df794c4c6bb03b617e8345
MD5 d9aeac66f0ba8b7953757ebac7d90a85
BLAKE2b-256 ef7f53defed471590b578f187cb42aefab770ee58ae6437dbe6badf2aafb871e

See more details on using hashes here.

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