Skip to content

Commit a6e91bb

Browse files
committed
refact: make code less complex.
1 parent 6f39251 commit a6e91bb

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ lint:
7575
@echo "--> Linting code"
7676
@make ruff
7777
uv run mypy packages/hop3-server/src
78-
cd packages/hop3-server && uv run deptry src
78+
# cd packages/hop3-server && uv run deptry src
7979
@echo ""
8080

8181
## Alias for lint (used by CI)

packages/hop3-tui/src/hop3_tui/screens/chat.py

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -278,42 +278,34 @@ def _process_command(self, command: str) -> None:
278278
cmd = parts[0].lower() if parts else ""
279279
args = parts[1:] if len(parts) > 1 else []
280280

281-
match cmd:
282-
case "?" | "help":
283-
self._show_help()
284-
case "apps":
285-
self._cmd_apps()
286-
case "app":
287-
if args:
288-
self._cmd_app_detail(args[0])
289-
else:
290-
self._add_error_message("Usage: app <name>")
291-
case "start":
292-
if args:
293-
self._cmd_start(args[0])
294-
else:
295-
self._add_error_message("Usage: start <app_name>")
296-
case "stop":
297-
if args:
298-
self._cmd_stop(args[0])
299-
else:
300-
self._add_error_message("Usage: stop <app_name>")
301-
case "restart":
302-
if args:
303-
self._cmd_restart(args[0])
304-
else:
305-
self._add_error_message("Usage: restart <app_name>")
306-
case "logs":
307-
if args:
308-
self._cmd_logs(args[0])
309-
else:
310-
self._add_error_message("Usage: logs <app_name>")
311-
case "status":
312-
self._cmd_status()
313-
case "clear":
314-
self._cmd_clear()
315-
case _:
316-
self._add_error_message(f"Unknown command: {cmd}\nType ? for help")
281+
# Commands that don't require arguments
282+
simple_commands = {
283+
"?": self._show_help,
284+
"help": self._show_help,
285+
"apps": self._cmd_apps,
286+
"status": self._cmd_status,
287+
"clear": self._cmd_clear,
288+
}
289+
290+
# Commands that require an app name argument
291+
app_commands = {
292+
"app": (self._cmd_app_detail, "app <name>"),
293+
"start": (self._cmd_start, "start <app_name>"),
294+
"stop": (self._cmd_stop, "stop <app_name>"),
295+
"restart": (self._cmd_restart, "restart <app_name>"),
296+
"logs": (self._cmd_logs, "logs <app_name>"),
297+
}
298+
299+
if cmd in simple_commands:
300+
simple_commands[cmd]()
301+
elif cmd in app_commands:
302+
handler, usage = app_commands[cmd]
303+
if args:
304+
handler(args[0])
305+
else:
306+
self._add_error_message(f"Usage: {usage}")
307+
else:
308+
self._add_error_message(f"Unknown command: {cmd}\nType ? for help")
317309

318310
def _show_help(self) -> None:
319311
"""Show help message."""

ruff.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,12 @@ lint.extend-ignore = [
6262
"F841", # [ ] unused-variable
6363
"PLR0915", # [ ] too-many-statements
6464
"B904", # [ ] raise-without-from-inside-except
65-
"PLR0912", # [ ] too-many-branches
6665
"PLW0603", # [ ] global-statement
6766
"E402", # [ ] module-import-not-at-top-of-file
6867
"EXE001", # [ ] shebang-not-executable
6968
"PLR0911", # [ ] too-many-return-statements
7069
"PLW1508", # [ ] invalid-envvar-default
7170
"TC001", # [ ] typing-only-first-party-import
72-
"C901", # [ ] complex-structure
7371
"RUF005", # [ ] collection-literal-concatenation
7472
"DTZ005", # [ ] call-datetime-now-without-tzinfo
7573
"PERF203", # [ ] try-except-in-loop

0 commit comments

Comments
 (0)