CliKit

0.6.2 · maintenance · verified Sun Apr 12

CliKit is a Python library providing a collection of utilities to build robust and testable command-line interfaces. It serves as a foundational component for other CLI frameworks like Cleo. The library is currently at version 0.6.2, with its last release in June 2020, indicating a maintenance phase following a period of active development in late 2019 and early 2020.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a simple CLI application with a single 'hello' command that accepts a required argument for a name and an optional flag to make the greeting loud. It initializes an `Application`, adds the custom `HelloCommand`, and runs the application.

from clikit.api.application import Application
from clikit.api.command import Command
from clikit.api.args import Argument, Option
from clikit.ui.io import IO


class HelloCommand(Command):
    def __init__(self):
        super().__init__()
        self.set_name("hello")
        self.set_description("Greets the given name.")
        self.add_argument(Argument("name", Argument.REQUIRED, "The name to greet."))
        self.add_option(Option("loud", "l", Option.NO_VALUE, "Make the greeting loud."))

    def handle(self, io: IO):
        name = io.args.get("name")
        loud = io.args.get("loud")

        message = f"Hello, {name}!"
        if loud:
            message = message.upper()

        io.write_line(message)


if __name__ == "__main__":
    application = Application("My CLI App", "1.0.0")
    application.add_command(HelloCommand())
    application.run()

view raw JSON →