Add init command and first-run guidance flow
This commit is contained in:
parent
e262b26db7
commit
706d9e2da7
2 changed files with 38 additions and 0 deletions
|
|
@ -470,6 +470,7 @@ def _init_command(args: argparse.Namespace) -> int:
|
|||
def _run_command(args: argparse.Namespace) -> int:
|
||||
global _LOCK_HANDLE
|
||||
config_path = Path(args.config) if args.config else DEFAULT_CONFIG_PATH
|
||||
config_existed_before_start = config_path.exists()
|
||||
|
||||
try:
|
||||
cfg = load(str(config_path))
|
||||
|
|
@ -489,6 +490,9 @@ def _run_command(args: argparse.Namespace) -> int:
|
|||
str(config_path),
|
||||
json.dumps(redacted_dict(cfg), indent=2),
|
||||
)
|
||||
if not config_existed_before_start and config_path.exists():
|
||||
logging.info("created default config at %s", config_path)
|
||||
logging.info("next step: run `aman doctor --config %s`", config_path)
|
||||
logging.info(
|
||||
"runtime: pid=%s session=%s display=%s wayland_display=%s verbose=%s dry_run=%s",
|
||||
os.getpid(),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import io
|
||||
import json
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
|
@ -53,6 +54,39 @@ class AmanCliTests(unittest.TestCase):
|
|||
self.assertEqual(exit_code, 2)
|
||||
self.assertIn("[FAIL] config.load", out.getvalue())
|
||||
|
||||
def test_init_command_creates_default_config(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
args = aman._parse_cli_args(["init", "--config", str(path)])
|
||||
|
||||
exit_code = aman._init_command(args)
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertTrue(path.exists())
|
||||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
self.assertIn("daemon", payload)
|
||||
|
||||
def test_init_command_refuses_overwrite_without_force(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text('{"daemon":{"hotkey":"Super+m"}}\n', encoding="utf-8")
|
||||
args = aman._parse_cli_args(["init", "--config", str(path)])
|
||||
|
||||
exit_code = aman._init_command(args)
|
||||
self.assertEqual(exit_code, 1)
|
||||
self.assertIn("Super+m", path.read_text(encoding="utf-8"))
|
||||
|
||||
def test_init_command_force_overwrites_existing_config(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text('{"daemon":{"hotkey":"Super+m"}}\n', encoding="utf-8")
|
||||
args = aman._parse_cli_args(["init", "--config", str(path), "--force"])
|
||||
|
||||
exit_code = aman._init_command(args)
|
||||
self.assertEqual(exit_code, 0)
|
||||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
self.assertEqual(payload["daemon"]["hotkey"], "Cmd+m")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue