Skip to content

cli

Module that contains the command line application.

Functions:

apply_credentials

apply_credentials(*services: str) -> None

Apply credentials for AWS and Hugging Face.

This function is called when the program starts. It hides the credentials for AWS and Hugging Face in a hidden directory.

Source code in src/unibox/cli.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def apply_credentials(*services: str) -> None:
    """Apply credentials for AWS and Hugging Face.

    This function is called when the program starts.
    It hides the credentials for AWS and Hugging Face in a hidden directory.
    """
    if not services:
        services = ["aws", "huggingface"]
    try:
        print(f"Applying credentials: {services}")
        _apply_credentials(*services)
    except Exception as e:
        print(f"Error applying credentials: {e}")
        sys.exit(1)

get_parser

get_parser() -> ArgumentParser

Return the CLI argument parser.

Source code in src/unibox/cli.py
49
50
51
52
53
54
55
56
57
58
59
60
61
def get_parser() -> argparse.ArgumentParser:
    """Return the CLI argument parser."""
    parser = argparse.ArgumentParser(prog="unibox")
    parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {debug.get_version()}")
    parser.add_argument("--debug-info", action=_DebugInfo, help="Print debug information.")

    subparsers = parser.add_subparsers(dest="command", required=True)

    # Add `apply-cred` command
    subparsers.add_parser("apply-cred", help="Apply credentials for AWS and Hugging Face. Hides them if not hidden")
    subparsers.add_parser("ac", help="Alias for apply-cred")

    return parser

main

main(args: list[str] | None = None) -> int

Run the main program.

This function is executed when you type unibox or python -m unibox.

Parameters:

  • args (list[str] | None, default: None ) –

    Arguments passed from the command line.

Returns:

  • int

    An exit code.

Source code in src/unibox/cli.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def main(args: list[str] | None = None) -> int:
    """Run the main program.

    This function is executed when you type `unibox` or `python -m unibox`.

    Parameters:
        args: Arguments passed from the command line.

    Returns:
        An exit code.
    """
    parser = get_parser()
    opts = parser.parse_args(args=args)

    if opts.command in ("apply-cred", "ac"):
        apply_credentials()
        return 0

    parser.print_help()
    return 1