Skip to main content

Python CLI framework with well defined argument rules and automatic help string generation.

Project description

FREYA CLI

Freya CLI (FRamEwork for pYthon Applications) is, as the name suggests, a Python framework for building Command Line Interface (CLI) applications. It allows developers to use a set of well defined rules and specifications for the intended usage of the CLI (via the FYR format), while giving an intuitive idea to the users on how the app's CLI expects to receive.

As a bonus, Freya CLI provides a simple utility for coloring any printed text, via the freyacli.Color class. The colors provided are black, white, red, green, blue, yellow, magenta, cyan; with their respective bright variations, for a total of 16 colors.

FYR / FYH format

  • FYR (FreYa Rules) specifies a list of rules that must be followed when using an application's CLI. These rules are organized inside a hierarchy structure composed of subcommand nodes.
  • FYH (FreYa Helps) should follow the same structure as its respective FYR. Instead of specifying the CLI rules, it stores the help strings that will be displayed whenever an incorrect use of the CLI is detected.

Below is an explanation of the argument rules and the subcommand nodes.

Argument Rules

Argument rules specify how the arguments should be passed to the CLI, and are specified in the FYR format. The simplest rule has the form:

name[]1.STR

where name is both the name that will be used to fetch the user values, and the name displayed in the automatic help string. The empty brackets represent that this argument is positional (e.g. like how the argument is passed to the command cat README.md). The expected type is passed after a ., in this case STR (1 indicates that one value is expected, more on that later). Supported types are:

  • STR: string
  • PATH: Python Path instance
  • INT: integer
  • FLOAT: float

If the argument is intended to be a simple on/off flag instead (e.g. -a in ls -a), it would instead look like

name[a,all]

This means that the flag name can be toggled on by passing either the flag -a (short name) or --all (long name). Short names can only be 1-character long; numbers are currently not allowed. If only a short name is to be defined, you can write it as [a,]; if only a long name is needed instead, it can be written as [,all].

Naturally, toggle flags should be optional by nature. To indicate that an argument is optional, a `~``char should be placed in front of the name. This applies to any kind of argument, be it positional or flags. So the previous example would be:

~name[a,all]

Flags can also have a value attached to them. It will look similar to the positional argument syntax, with the added short/long flag names inside the brackets, e.g.:

~path_file[i,input]1.PATH

Finally, default values can be specified inside the FYR too. These will be assigned to optional arguments that the user didn't specify. It uses a = at the end of the rule (limitation: spaces are not allowed inside default values), e.g.:

~path_file[i,input]1.PATH=README.md

Argument Count

...

Subcommands

...

Macros

...

Help String

...

Current limitations (TODO)

  • Default values shouldn't have spaces or newlines inside
  • Flag --help/-h is currently reserved.
  • Positional arguments / options (flags) aren't currently supported for non-leaf subcommand nodes.
  • Execution of the app must currently happen at a leaf subcommand node.
  • Short flag names should not be a digit. Otherwise the parser will confuse it as a float value (e.g. -3).

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

freyacli-0.1.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

freyacli-0.1.1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file freyacli-0.1.1.tar.gz.

File metadata

  • Download URL: freyacli-0.1.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for freyacli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 adea3b14c021544c11b7ccee28e6781268b38c0a617fb2a8b9f8476682e60e83
MD5 e105ca1bbc8e67fcdbef2bd3da7d4ad2
BLAKE2b-256 d804ca8c3dd4c062d3770d2d8325271ab12dabde2715a66ca089a7b6a3525811

See more details on using hashes here.

File details

Details for the file freyacli-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: freyacli-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for freyacli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35c584faeb411536778aabfcaee81fa4fa52232a8c61afaa48755566247fbdc0
MD5 6d1c4c35f3fab1496a3a95c68b966e5f
BLAKE2b-256 95d1dd89b85d5f21e3c848b70fbfd24993c80b206e6fb20c1fd6d1a67cc69b97

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