Utils Command API Reference¶
This section documents the internals of the utils
command in Bijux CLI.
bijux_cli.commands.plugins.utils ¶
Provides shared utilities for the bijux plugins
command group.
This module centralizes common logic for managing CLI plugins. It offers helper functions for tasks such as:
- Safely traversing plugin directories for copy operations.
- Parsing metadata from
plugin.py
files without code execution by using the Abstract Syntax Tree (AST). - Performing security checks, like refusing to operate on directories that are symbolic links.
- Validating plugin names against a standard pattern.
ignore_hidden_and_broken_symlinks ¶
Creates a list of files and directories to ignore during a copy operation.
This function is designed to be used as the ignore
callable for shutil.copytree
. It skips hidden files (starting with "."), the plugin.py
file, and any broken symbolic links.
Parameters:
-
dirpath
(str
) –The path to the directory being scanned.
-
names
(list[str]
) –A list of names of items within
dirpath
.
Returns:
-
list[str]
–list[str]: A list of item names to be ignored by
shutil.copytree
.
Source code in src/bijux_cli/commands/plugins/utils.py
parse_required_cli_version ¶
Parses requires_cli_version
from a plugin file without executing it.
This function safely inspects a Python file using the Abstract Syntax Tree (AST) to find the value of a top-level or class-level variable named requires_cli_version
. This avoids the security risks of importing or executing untrusted code.
Parameters:
-
plugin_py
(Path
) –The path to the
plugin.py
file to parse.
Returns:
-
str | None
–str | None: The version specifier string if found, otherwise None.
Source code in src/bijux_cli/commands/plugins/utils.py
refuse_on_symlink ¶
refuse_on_symlink(
directory: Path,
command: str,
fmt: str,
quiet: bool,
verbose: bool,
debug: bool,
) -> None
Emits an error and exits if the given directory is a symbolic link.
This serves as a security precaution to prevent plugin operations on unexpected filesystem locations.
Parameters:
-
directory
(Path
) –The path to check.
-
command
(str
) –The invoking command name for the error payload.
-
fmt
(str
) –The requested output format for the error payload.
-
quiet
(bool
) –If True, suppresses output before exiting.
-
verbose
(bool
) –If True, includes runtime info in the error payload.
-
debug
(bool
) –If True, enables debug diagnostics.
Returns:
-
None
(None
) –
Raises:
-
SystemExit
–Always exits the process with code 1 if
directory
is a symbolic link.