Skip to content

cli

CLI application and utilities.

CLI help autogenerated from versort --help-all:

versort 0.0.0

A simple version sorter CLI app.

Supported algorithms: PEP440, SemVer.

Usage:
    versort [SWITCHES] algorithm versions...

Meta-switches:
    -h, --help                     Prints this help message and quits
    --help-all                     Prints help messages of all sub-commands and
                                   quits
    -v, --version                  Prints the program's version and quits

Switches:
    -f, --first                    Print only first match
    -i, --stdin                    Read tags from STDIN
    -r, --reverse                  Reverse order
    -s, --separator VALUE:str      Separator used when printing sorted results;
                                   the default is a new line

VerSortApp

A simple version sorter CLI app.

Supported algorithms: PEP440, SemVer.

main(self, algorithm, *versions)

Main entrypoint for CLI executions.

Parameters:

Name Type Description Default
algorithm str

Used to obtain the sorter, passed to get_sorter.

required
*versions str

Version strings to be sorted.

()
Source code in versort/cli.py
def main(self, algorithm: str, *versions: str):
    """Main entrypoint for CLI executions.

    Args:
        algorithm:
            Used to obtain the sorter, passed to
            [get_sorter][versort.base.get_sorter].

        *versions:
            Version strings to be sorted.
    """
    sorter = get_sorter(algorithm)()
    if self.stdin:
        versions = tuple(sys.stdin.read().split())
    sorted_versions = sorter.sort(*versions, reverse=self.reverse)
    if self.first:
        print(sorted_versions[0])
        return
    separator = os.linesep if self.separator is None else self.separator
    print(*sorted_versions, sep=separator)