config.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """``hermes config`` subcommand parser."""
  2. from __future__ import annotations
  3. from typing import Callable
  4. from hermes_cli.subcommands._shared import add_json_flag
  5. def build_config_parser(subparsers, *, cmd_config: Callable) -> None:
  6. """Attach the ``config`` subcommand to ``subparsers``."""
  7. config_parser = subparsers.add_parser(
  8. "config", help="View and edit configuration",
  9. description="Manage Hermes Agent configuration")
  10. config_subparsers = config_parser.add_subparsers(dest="config_command")
  11. config_subparsers.add_parser("show", help="Show current configuration")
  12. config_subparsers.add_parser("edit", help="Open config file in editor")
  13. config_get = config_subparsers.add_parser("get", help="Print a resolved configuration value")
  14. config_get.add_argument("key", nargs="?", help="Configuration key (e.g., model)")
  15. add_json_flag(config_get, "Print value as JSON")
  16. config_get.add_argument(
  17. "--raw", action="store_true",
  18. help="Print credential values unmasked (default masks api_key/token/secret-shaped values)")
  19. config_set = config_subparsers.add_parser("set", help="Set a configuration value")
  20. config_set.add_argument(
  21. "key", nargs="?", help="Configuration key (e.g., model, terminal.backend)")
  22. config_set.add_argument("value", nargs="?", help="Value to set")
  23. config_set.add_argument(
  24. "--force", action="store_true",
  25. help="Write a key the running version doesn't recognize: an unknown path under a known "
  26. "section is otherwise refused, and an unknown top-level key is written with a notice.")
  27. config_unset = config_subparsers.add_parser("unset", help="Remove a configuration value")
  28. config_unset.add_argument("key", nargs="?", help="Configuration key to remove")
  29. config_subparsers.add_parser("path", help="Print config file path")
  30. config_subparsers.add_parser("env-path", help="Print .env file path")
  31. config_subparsers.add_parser("check", help="Check for missing/outdated config")
  32. config_subparsers.add_parser("migrate", help="Update config with new options")
  33. config_parser.set_defaults(func=cmd_config)