reorder cli commands navigations are now into a nav sub group

This commit is contained in:
2026-04-08 22:20:23 +02:00
parent 4880b34792
commit e954f53758
4 changed files with 29 additions and 31 deletions
+11 -11
View File
@@ -105,26 +105,26 @@ browser-cli/
All commands are run with `uv run browser-cli <command>`. All commands are run with `uv run browser-cli <command>`.
### Navigation ### Navigation (`nav`)
```sh ```sh
# Open a URL # Open a URL
browser-cli open https://example.com browser-cli nav open https://example.com
browser-cli open https://example.com --bg # background, no focus browser-cli nav open https://example.com --bg # background, no focus
browser-cli open https://example.com --window work # into a named window browser-cli nav open https://example.com --window work # into a named window
browser-cli open https://example.com --group research # into a tab group (name or ID) browser-cli nav open https://example.com --group research # into a tab group (name or ID)
# Reload # Reload
browser-cli reload # reload active tab browser-cli nav reload # reload active tab
browser-cli reload 1234 # reload tab by ID browser-cli nav reload 1234 # reload tab by ID
browser-cli hard-reload # bypass cache browser-cli nav hard-reload # bypass cache
# Navigate history # Navigate history
browser-cli back browser-cli nav back
browser-cli forward 1234 # forward in specific tab browser-cli nav forward 1234 # forward in specific tab
# Jump to a tab by URL pattern # Jump to a tab by URL pattern
browser-cli focus github # focuses first tab whose URL contains "github" browser-cli nav focus github # focuses first tab whose URL contains "github"
``` ```
### Tabs ### Tabs
Regular → Executable
+3 -10
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env -S uv run
""" """
browser-cli — Control your running browser from the terminal. browser-cli — Control your running browser from the terminal.
""" """
@@ -10,7 +10,7 @@ import stat
from pathlib import Path from pathlib import Path
from rich.console import Console from rich.console import Console
from browser_cli.commands.navigate import cmd_open, cmd_reload, cmd_hard_reload, cmd_back, cmd_forward, cmd_focus from browser_cli.commands.navigate import nav_group
from browser_cli.commands.tabs import tabs_group from browser_cli.commands.tabs import tabs_group
from browser_cli.commands.groups import group_group from browser_cli.commands.groups import group_group
from browser_cli.commands.windows import windows_group from browser_cli.commands.windows import windows_group
@@ -44,15 +44,8 @@ def main():
"""Control your running browser from the terminal via a Chrome extension.""" """Control your running browser from the terminal via a Chrome extension."""
# ── Top-level navigation commands ─────────────────────────────────────────────
main.add_command(cmd_open, name="open")
main.add_command(cmd_reload, name="reload")
main.add_command(cmd_hard_reload, name="hard-reload")
main.add_command(cmd_back, name="back")
main.add_command(cmd_forward, name="forward")
main.add_command(cmd_focus, name="focus")
# ── Sub-command groups ───────────────────────────────────────────────────────── # ── Sub-command groups ─────────────────────────────────────────────────────────
main.add_command(nav_group)
main.add_command(tabs_group) main.add_command(tabs_group)
main.add_command(group_group) main.add_command(group_group)
main.add_command(windows_group) main.add_command(windows_group)
+12 -7
View File
@@ -16,14 +16,19 @@ def _handle(command, args):
raise SystemExit(1) raise SystemExit(1)
@click.command("open") @click.group("nav")
def nav_group():
"""Navigate — open URLs, reload, go back/forward, focus tabs."""
@nav_group.command("open")
@click.argument("url") @click.argument("url")
@click.option("--bg", is_flag=True, help="Open in background (no focus)") @click.option("--bg", is_flag=True, help="Open in background (no focus)")
@click.option("--window", "window_name", default=None, help="Open in named window") @click.option("--window", "window_name", default=None, help="Open in named window")
@click.option("--group", "group_name", default=None, help="Open directly into a tab group (name or ID)") @click.option("--group", "group_name", default=None, help="Open directly into a tab group (name or ID)")
def cmd_open(url, bg, window_name, group_name): def cmd_open(url, bg, window_name, group_name):
"""Open URL in a new tab.""" """Open URL in a new tab."""
result = _handle("navigate.open", {"url": url, "background": bg, "window": window_name, "group": group_name}) _handle("navigate.open", {"url": url, "background": bg, "window": window_name, "group": group_name})
suffix = "" suffix = ""
if group_name: if group_name:
suffix = f" in group '{group_name}'" suffix = f" in group '{group_name}'"
@@ -32,7 +37,7 @@ def cmd_open(url, bg, window_name, group_name):
console.print(f"[green]Opened:[/green] {url}{suffix}") console.print(f"[green]Opened:[/green] {url}{suffix}")
@click.command("reload") @nav_group.command("reload")
@click.argument("tab_id", type=int, required=False) @click.argument("tab_id", type=int, required=False)
def cmd_reload(tab_id): def cmd_reload(tab_id):
"""Reload the active (or specified) tab.""" """Reload the active (or specified) tab."""
@@ -40,7 +45,7 @@ def cmd_reload(tab_id):
console.print("[green]Reloaded[/green]") console.print("[green]Reloaded[/green]")
@click.command("hard-reload") @nav_group.command("hard-reload")
@click.argument("tab_id", type=int, required=False) @click.argument("tab_id", type=int, required=False)
def cmd_hard_reload(tab_id): def cmd_hard_reload(tab_id):
"""Hard reload (bypass cache) the active (or specified) tab.""" """Hard reload (bypass cache) the active (or specified) tab."""
@@ -48,7 +53,7 @@ def cmd_hard_reload(tab_id):
console.print("[green]Hard reloaded[/green]") console.print("[green]Hard reloaded[/green]")
@click.command("back") @nav_group.command("back")
@click.argument("tab_id", type=int, required=False) @click.argument("tab_id", type=int, required=False)
def cmd_back(tab_id): def cmd_back(tab_id):
"""Navigate back in the active (or specified) tab.""" """Navigate back in the active (or specified) tab."""
@@ -56,7 +61,7 @@ def cmd_back(tab_id):
console.print("[green]Navigated back[/green]") console.print("[green]Navigated back[/green]")
@click.command("forward") @nav_group.command("forward")
@click.argument("tab_id", type=int, required=False) @click.argument("tab_id", type=int, required=False)
def cmd_forward(tab_id): def cmd_forward(tab_id):
"""Navigate forward in the active (or specified) tab.""" """Navigate forward in the active (or specified) tab."""
@@ -64,7 +69,7 @@ def cmd_forward(tab_id):
console.print("[green]Navigated forward[/green]") console.print("[green]Navigated forward[/green]")
@click.command("focus") @nav_group.command("focus")
@click.argument("pattern") @click.argument("pattern")
def cmd_focus(pattern): def cmd_focus(pattern):
"""Jump to the first tab whose URL matches PATTERN.""" """Jump to the first tab whose URL matches PATTERN."""
+3 -3
View File
@@ -43,8 +43,8 @@ pause
header "3/8 · Create 'research' group and open URLs into it" header "3/8 · Create 'research' group and open URLs into it"
$CLI group create research $CLI group create research
echo "" echo ""
$CLI open https://example.com --group research --bg $CLI nav open https://example.com --group research --bg
$CLI open https://wikipedia.org --group research --bg $CLI nav open https://wikipedia.org --group research --bg
echo "" echo ""
echo " Tabs are now open inside the 'research' group in your browser." echo " Tabs are now open inside the 'research' group in your browser."
pause pause
@@ -63,7 +63,7 @@ pause
header "6/8 · DOM and content extraction (active tab)" header "6/8 · DOM and content extraction (active tab)"
echo " Switching to the example.com tab first..." echo " Switching to the example.com tab first..."
$CLI focus example.com $CLI nav focus example.com
echo "" echo ""
echo " Page headings:" echo " Page headings:"
$CLI dom text h1 $CLI dom text h1