Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions backend/internal/cli/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ func newPreviewCommand(ctx *commandContext) *cobra.Command {
Use: "preview [url]",
Short: "Open a URL (or the workspace's index.html) in the desktop browser panel for the current session",
Long: "Open a URL in the desktop browser panel for the current session.\n\n" +
"With no argument it opens the workspace's index.html. A workspace-relative path\n" +
"(e.g. ./dist/index.html) is served as a local file. Use `ao preview\n" +
"clear` to empty the panel.",
"With no argument it opens the workspace's static entry point, falling\n" +
"back to this session's existing preview target when no entry point exists.\n" +
"A local file can be opened by its absolute file:// URL\n" +
"(e.g. file:///home/me/proj/index.html). Use `ao preview clear` to empty the panel.",
Example: ` ao preview
ao preview file://$(pwd)/index.html
ao preview http://localhost:5173
ao preview clear`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var target string
Expand Down
18 changes: 18 additions & 0 deletions backend/internal/cli/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ func TestPreview_MissingSessionIDIsUsageError(t *testing.T) {
}
}

func TestPreview_HelpIncludesExamples(t *testing.T) {
out, _, err := executeCLI(t, Deps{}, "preview", "--help")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// Examples section present.
if !strings.Contains(out, "EXAMPLES") && !strings.Contains(out, "Examples") {
t.Errorf("help output missing Examples section:\n%s", out)
}
// file:// URL example (not a relative path).
if !strings.Contains(out, "file://$(pwd)/index.html") {
t.Errorf("help output missing file:// example:\n%s", out)
}
if strings.Contains(out, "./dist/index.html") {
t.Errorf("help output still references relative ./dist/index.html:\n%s", out)
}
}

func TestPreview_BlankSessionIDIsUsageError(t *testing.T) {
t.Setenv("AO_SESSION_ID", " \t ")
cfg := setConfigEnv(t)
Expand Down
Loading