Coverage for /home/runner/work/bijux-cli/bijux-cli/src/bijux_cli/commands/config/__init__.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.10.4, created at 2025-08-19 23:36 +0000

1# SPDX-License-Identifier: MIT 

2# Copyright © 2025 Bijan Mousavi 

3 

4"""Defines the `config` command group for the Bijux CLI. 

5 

6This module serves as the central entry point for all configuration management 

7functionality. It aggregates the various subcommands into a single `Typer` 

8application, creating the `bijux config` command hierarchy. 

9 

10The `config` command, when run without a subcommand, lists all current 

11key-value pairs. 

12 

13The available subcommands are: 

14 * `set`: Sets a key-value pair. 

15 * `get`: Retrieves the value for a specific key. 

16 * `unset`: Removes a key-value pair. 

17 * `list`: Lists all defined configuration keys. 

18 * `clear`: Removes all key-value pairs from the configuration. 

19 * `load`: Replaces the current configuration with one from a file. 

20 * `reload`: Forces a reload of the configuration from its source file. 

21 * `export`: Writes the current configuration to a file or stdout. 

22 

23Exit codes for the subcommands generally follow this pattern: 

24 * `0`: Success. 

25 * `1`: An internal or unexpected error occurred. 

26 * `2`: An invalid argument was provided (e.g., bad format, key not found). 

27 * `3`: An ASCII or encoding error was detected. 

28""" 

29 

30from __future__ import annotations 

31 

32import typer 

33 

34from bijux_cli.commands.config.clear import clear_config 

35from bijux_cli.commands.config.export import export_config 

36from bijux_cli.commands.config.get import get_config 

37from bijux_cli.commands.config.list_cmd import list_config 

38from bijux_cli.commands.config.load import load_config 

39from bijux_cli.commands.config.reload import reload_config 

40from bijux_cli.commands.config.service import config 

41from bijux_cli.commands.config.set import set_config 

42from bijux_cli.commands.config.unset import unset_config 

43 

44typer.core.rich = None # type: ignore[attr-defined,assignment] 

45 

46config_app = typer.Typer( # pytype: skip-file 

47 name="config", 

48 help="Manage CLI configuration.", 

49 rich_markup_mode=None, 

50 context_settings={"help_option_names": ["-h", "--help"]}, 

51 no_args_is_help=False, 

52) 

53 

54config_app.callback(invoke_without_command=True)(config) 

55 

56config_app.command("clear")(clear_config) 

57config_app.command("export")(export_config) 

58config_app.command("get")(get_config) 

59config_app.command("list")(list_config) 

60config_app.command("load")(load_config) 

61config_app.command("reload")(reload_config) 

62config_app.command("set")(set_config) 

63config_app.command("unset")(unset_config) 

64 

65 

66@config_app.command("import", hidden=True) 

67def import_config(*args, **kwargs) -> None: # type: ignore 

68 """Provides a backward-compatibility alias for the `config load` command. 

69 

70 This command is hidden from the main help text and delegates directly to 

71 `load_config`, forwarding all arguments. 

72 

73 Args: 

74 *args: Positional arguments to forward to `load_config`. 

75 **kwargs: Keyword arguments to forward to `load_config`. 

76 

77 Returns: 

78 None: 

79 """ 

80 return load_config(*args, **kwargs) 

81 

82 

83__all__ = [ 

84 "config_app", 

85]