Skip to content

bmctools.cli.commands.common

Common command utilities shared across all commands.

wrap_command

def wrap_command(func: Callable[[argparse.Namespace], Any], args: argparse.Namespace) -> int

Wrap command execution with common error handling.

Args: func: Command function to execute args: Parsed arguments

Returns: Exit code (0 for success, non-zero for error)

Parameters:

NameTypeDefaultDescription
funcCallable[[argparse.Namespace], Any]
argsargparse.Namespace

Returns: int

read_file_lines

def read_file_lines(file_path: str) -> list

Read lines from a file.

Args: file_path: Path to file

Returns: List of lines (stripped of whitespace)

Raises: FileNotFoundError: If file doesn’t exist

Parameters:

NameTypeDefaultDescription
file_pathstr

Returns: list

parse_comma_list

def parse_comma_list(value: str) -> list

Parse comma-separated list.

Args: value: Comma-separated string

Returns: List of strings

Parameters:

NameTypeDefaultDescription
valuestr

Returns: list

confirm_action

def confirm_action(prompt: str, force: bool = False) -> bool

Prompt user for confirmation on destructive operations.

Args: prompt: Confirmation prompt message force: If True, skip confirmation and return True

Returns: True if confirmed, False otherwise

Parameters:

NameTypeDefaultDescription
promptstr
forceboolFalse

Returns: bool

show_progress

def show_progress(message: str, done: bool = False) -> None

Display progress indicator.

Args: message: Progress message done: If True, show completion, else show in-progress

Parameters:

NameTypeDefaultDescription
messagestr
doneboolFalse

Returns: None

validate_file_exists

def validate_file_exists(file_path: str) -> None

Validate that a file exists.

Args: file_path: Path to file

Raises: FileNotFoundError: If file doesn’t exist

Parameters:

NameTypeDefaultDescription
file_pathstr

Returns: None

parse_key_value_pairs

def parse_key_value_pairs(pairs: list) -> dict

Parse key=value pairs from list of strings.

Args: pairs: List of “key=value” strings

Returns: Dict of key-value pairs

Raises: ValueError: If format is invalid

Parameters:

NameTypeDefaultDescription
pairslist

Returns: dict