Skip to content

CLI

Biscuit provides a command line interface (CLI) to interact with the main application. The CLI is a powerful tool that allows you to perform a wide range of operations, such as managing extensions, files, and settings.

  • General Commands


    General commands to manage the application, files, settings, and more

    Overview

  • Editor Commands


    Commands to manage the editor, files, settings, and more

    Editor

  • Git Commands


    Commands to manage Git repositories, branches, commits, and more

    Git

  • Extension Commands


    Commands to manage extensions, install, update, and more

    Extensions

Overview

cli(path=None, dev=False)

Biscuit CLI

Source code in src/biscuit/cli/cli.py
@click.group(cls=BiscuitCLI, invoke_without_command=True)
@click.version_option(__version__, "-v", "--version", message="Biscuit v%(version)s")
@click.help_option("-h", "--help")
@click.option("--dev", is_flag=True, help="Run in development mode")
def cli(path=None, dev=False):
    """Biscuit CLI"""

    click.echo(f"Biscuit v{__version__} {'(dev) 🚧' if dev else '🚀'}")

docs()

Open biscuit documentation

This command will open the biscuit documentation in the default browser.

Example

biscuit doc

Source code in src/biscuit/cli/cli.py
@cli.command("doc")
def docs():
    """Open biscuit documentation

    This command will open the biscuit documentation in the default browser.

    Example:
        biscuit doc
    """

    click.launch("https://tomlin7.github.io/biscuit/")
    exit()

run()

Setup the CLI and run the CLI

Source code in src/biscuit/cli/cli.py
def run():
    """Setup the CLI and run the CLI"""

    setup()
    cli()

setup()

Setup the CLI commands

Loads all the commands from the cli extensions and registers them

Source code in src/biscuit/cli/cli.py
def setup():
    """Setup the CLI commands

    Loads all the commands from the cli extensions and registers them"""

    extensions.register(cli)
    git.register(cli)
    editor.register(cli)

Editor Commands

goto(path=None, linecol=None)

Open a file and go to a specific location

This command will open a file and go to a specific location.

Example

biscuit goto path/to/file line

biscuit goto path/to/file line:column

Parameters:

Name Type Description Default
path str

The path to the file. Defaults to None.

None
linecol str

The line and column to go to. Defaults to None.

None
Source code in src/biscuit/cli/editor.py
@click.command()
@click.argument(
    "path",
    type=click.Path(
        exists=True,
        dir_okay=False,
        resolve_path=True,
    ),
    required=False,
)
@click.argument("linecol", type=str, required=False)
def goto(path=None, linecol=None) -> typing.Callable[[App, str], None]:
    """Open a file and go to a specific location

    This command will open a file and go to a specific location.

    Example:
        biscuit goto path/to/file line \n
        biscuit goto path/to/file line:column

    Args:
        path (str, optional): The path to the file. Defaults to None.
        linecol (str, optional): The line and column to go to. Defaults to None.
    """

    if not path:
        path = click.prompt("path/to/file", type=str)
    if not linecol:
        linecol = click.prompt("line:column", type=str)
    if not linecol:
        linecol = "1:1"

    # TODO: make the column optional

    return lambda app, path=path, linecol=linecol: app.goto_location(
        path, linecol.replace(":", ".")
    )

open(path=None)

Open a file or folder in the editor

This command will open a file or folder in the editor.

Example

biscuit open path/to/file

Parameters:

Name Type Description Default
path str

The path to the file or folder. Defaults to None.

None
Source code in src/biscuit/cli/editor.py
@click.command()
@click.argument(
    "path",
    type=click.Path(
        exists=True,
        dir_okay=True,
        resolve_path=True,
    ),
    required=False,
)
def open(path=None) -> typing.Callable[[App, str], None]:
    """Open a file or folder in the editor

    This command will open a file or folder in the editor.

    Example:
        biscuit open path/to/file

    Args:
        path (str, optional): The path to the file or folder. Defaults to None.
    """

    return lambda app, path=path: app.open(path)

Git Commands

clone(url)

Clone & open a git repository in Biscuit

This command will clone a git repository and open it in a new window.

Example

biscuit clone

Parameters:

Name Type Description Default
url str

The url of the git repository

required
Source code in src/biscuit/cli/git.py
@click.command()
@click.argument("url", type=str)
def clone(url) -> typing.Callable[[App, str], None]:
    """Clone & open a git repository in Biscuit

    This command will clone a git repository and open it in a new window.

    Example:
        biscuit clone

    Args:
        url (str): The url of the git repository
    """

    if not url:
        url = click.prompt("Git repository url", type=str)

    click.echo(
        f"Cloning repository from {'https://github.com/' if not URL.match(url) else ''}{url}"
    )
    return lambda app, url=url: app.clone_repo(url, new_window=False)

diff(file1=None, file2=None)

Diff two files

This command will open a new window with the diff of the two files.

Example

biscuit diff path/to/file path/to/second/file

Parameters:

Name Type Description Default
file1 str

The path to the first file. Defaults to None.

None
file2 str

The path to the second file. Defaults to None.

None
Source code in src/biscuit/cli/git.py
@click.command()
@click.argument(
    "file1",
    type=click.Path(
        exists=True,
        dir_okay=False,
        resolve_path=True,
    ),
    required=False,
)
@click.argument(
    "file2",
    type=click.Path(
        exists=True,
        dir_okay=False,
        resolve_path=True,
    ),
    required=False,
)
def diff(file1=None, file2=None) -> typing.Callable[[App, str], None]:
    """Diff two files

    This command will open a new window with the diff of the two files.

    Example:
        biscuit diff path/to/file path/to/second/file

    Args:
        file1 (str, optional): The path to the first file. Defaults to None.
        file2 (str, optional): The path to the second file. Defaults to None."""

    if not file1:
        file1 = click.prompt("path/to/file", type=str)
    if not file2:
        file2 = click.prompt("path/to/second/file", type=str)

    return lambda app, file1=file1, file2=file2: app.diff_files(file1, file2)

Extension Commands

create()

Create a new extension from template

This command will create a new extension from the template

NOTE: This command is not yet implemented

Source code in src/biscuit/cli/extensions.py
@ext.command()
def create():
    """Create a new extension from template

    This command will create a new extension from the template

    NOTE: This command is not yet implemented
    """

    click.echo("Extension created!")

ext()

Commands for managing biscuit extensions

This command group allows you to manage biscuit extensions.

Example

biscuit ext list

biscuit ext install extension_name

biscuit ext uninstall extension_name

Source code in src/biscuit/cli/extensions.py
@click.group(invoke_without_command=True)
@click.help_option("-h", "--help")
def ext():
    """Commands for managing biscuit extensions

    This command group allows you to manage biscuit extensions.

    Example:
        biscuit ext list \n
        biscuit ext install extension_name \n
        biscuit ext uninstall extension_name
    """
    ...

info(name)

Show information about an extension by name

Example

biscuit ext info extension_name

Parameters:

Name Type Description Default
name str

The name of the extension

required
Source code in src/biscuit/cli/extensions.py
@ext.command()
@click.argument("name")
def info(name: str) -> typing.Callable[[App], None]:
    """Show information about an extension by name

    Example:
        biscuit ext info extension_name

    Args:
        name (str): The name of the extension"""

    def f(app: App, name=name) -> None:
        data = app.extensions_manager.find_extension_by_name(name)
        if data:
            click.echo(f"Name: {name}")
            click.echo(f"Author: {data[1]}")
            click.echo(f"Description: {data[2]}")
            # TODO: click.echo(f"Version: {data[3]}")
        else:
            click.echo(f"Could not find extension {name}")

    return f

install(name)

Install an extension by name

Example

biscuit ext install extension_name

Parameters:

Name Type Description Default
name str

The name of the extension

required
Source code in src/biscuit/cli/extensions.py
@ext.command()
@click.argument("name")
def install(name: str) -> typing.Callable[[App], None]:
    """Install an extension by name

    Example:
        biscuit ext install extension_name

    Args:
        name (str): The name of the extension
    """

    def f(app: App, name=name) -> None:
        if app.extensions_manager.install_extension_from_name(name):
            click.echo(f"Installed extension {name} successfully")
        else:
            click.echo(f"Could not find extension {name}")

    return f

list_ext(user, installed)

List all extensions or installed or filter by user

Example

biscuit ext list

biscuit ext list -u user

biscuit ext list -i

Parameters:

Name Type Description Default
user str

Filter by user

required
installed bool

Show installed extensions

required
Source code in src/biscuit/cli/extensions.py
@ext.command("list")
@click.option("-u", "--user", help="Filter by user")
@click.option("-i", "--installed", is_flag=True, help="Show installed extensions")
def list_ext(user, installed) -> typing.Callable[[App], typing.List[str]]:
    """List all extensions or installed or filter by user

    Example:
        biscuit ext list \n
        biscuit ext list -u user \n
        biscuit ext list -i

    Args:
        user (str): Filter by user
        installed (bool): Show installed extensions
    """

    if user:
        click.echo(f"Listing extensions by {user}\n")

        def f(app: App, user=user) -> None:
            for i, data in enumerate(
                app.extensions_manager.list_extensions_by_user(user)
            ):
                click.echo(f"[{i}] {data[0]}: " + data[1][-1])

        return f

    elif installed:
        click.echo("Listing installed extensions\n")

        def f(app: App) -> None:
            for i, data in enumerate(
                app.extensions_manager.list_installed_extensions()
            ):
                click.echo(
                    f"[{i}] {data[0]}: " + ", ".join(data[1]) if data[1] else " ... "
                )

        return f
    else:
        click.echo("Listing all extensions\n")

        def f(app: App) -> None:
            for i, data in enumerate(app.extensions_manager.list_all_extensions()):
                click.echo(f"[{i}] {data[0]}: " + ", ".join(data[1][1:]))

        return f

test()

Test the extension

This command will test your custom extension

NOTE: This command is not yet implemented

Source code in src/biscuit/cli/extensions.py
@ext.command()
def test():
    """Test the extension

    This command will test your custom extension

    NOTE: This command is not yet implemented
    """

    click.echo("Extension tested!")

uninstall(name)

Uninstall an extension by name

Example

biscuit ext uninstall extension_name

Parameters:

Name Type Description Default
name str

The name of the extension

required
Source code in src/biscuit/cli/extensions.py
@ext.command()
@click.argument("name")
def uninstall(name: str) -> typing.Callable[[App], None]:
    """Uninstall an extension by name

    Example:
        biscuit ext uninstall extension_name

    Args:
        name (str): The name of the extension
    """

    def f(app: App, name=name) -> None:
        if app.extensions_manager.uninstall_extension_from_name(name):
            click.echo(f"Uninstalled extension {name} successfully")
        else:
            click.echo(f"Could not find extension {name}")

    return f