Usage

Create a Clickfile

If you run klak without a Clickfile in the current working directory, you will probably see this:

Error: Could not find Clickfile!

The minimum to resolve that error would be:

# In the current directory
touch Clickfile

Notes:

  • Clickfile naming is required
  • klak currently only supports looking for the Clickfile in the current directory.

Klak Command-line Interface

klak doesn’t ship with any commands, but you can run the standard –help flag or just klak just the same.

# See available commands
klak --help

What is a Clickfile

A Clickfile is an allegory to the classic Makefile and is the intended destination for your project automation commands.

How to Use a Clickfile

There’s really zero magic going on here:

  1. Leverage Click to build your project automation command-line interface.
  2. Script Python as you normally would.

If you’re unfamiliar with Python scripting, here are some resources:

Example Clickfile

Here’s a simple Clickfile as an example. Head on over to the Click documentation to learn more about how to use Click.

"""My Project's Clickfile!"""

from klak.cli import root
import click


# `root` is provided by the `klak` package and you must
# _at least_ append a command to it to make it available.
@root.command()
def hello_world():
    """Hello world."""
    click.echo("hi")


# Create a nested command group.
@root.group()
def greetings():
    """Greeting commands"""
    pass


# Add a new command to the new group.
@greetings.command()
@click.option("--name", help="Who are you greeting?", required=True)
def say_hello(name):
    """Say hello to someone."""
    click.echo("Hello, " + name)


# Add another command!
@greetings.command()
@click.option("--name", help="Who are you wishing farewell?", required=True)
def say_goodbye(name):
    """Say goodbye to someone."""
    click.echo("Goodbye, " + name)

This file results in the following help string:

Usage: klak [OPTIONS] COMMAND [ARGS]...

Click n' Klak.

Options:
--help  Show this message and exit.

Commands:
hello_world  Hello World
greetings    Greeting commands

Enable Bash Completions

You can enable Bash Completions in the standard Click way:

eval "$(_KLAK_COMPLETE=source klak)"