Simplify page command

This commit is contained in:
2026-03-07 02:26:05 -06:00
parent 5929feef4f
commit 8601361598
4 changed files with 11 additions and 69 deletions
+1 -1
View File
@@ -13,7 +13,7 @@
"name": "wiki", "name": "wiki",
"source": "./plugins/rsw", "source": "./plugins/rsw",
"description": "RuneScape Wiki CLI", "description": "RuneScape Wiki CLI",
"version": "1.0.1", "version": "1.0.2",
"author": { "author": {
"name": "Sam Myers" "name": "Sam Myers"
} }
+2 -2
View File
@@ -1,9 +1,9 @@
{ {
"name": "runescape-wiki", "name": "runescape-wiki",
"description": "Query the RuneScape Wiki (RS3 and OSRS) for items, quests, skills, and Grand Exchange prices", "description": "Query the RuneScape Wiki (RS3 and OSRS) for items, quests, skills, and Grand Exchange prices",
"version": "1.0.0", "version": "1.0.2",
"author": { "author": {
"name": "sam" "name": "Sam Myers"
}, },
"keywords": ["runescape", "osrs", "rs3", "wiki", "grand-exchange", "gaming"] "keywords": ["runescape", "osrs", "rs3", "wiki", "grand-exchange", "gaming"]
} }
+4 -56
View File
@@ -2,7 +2,6 @@ package cmd
import ( import (
"fmt" "fmt"
"strings"
"github.com/runescape-wiki/rsw/internal/htmlconv" "github.com/runescape-wiki/rsw/internal/htmlconv"
"github.com/runescape-wiki/rsw/internal/render" "github.com/runescape-wiki/rsw/internal/render"
@@ -11,20 +10,15 @@ import (
) )
func newPageCmd() *cobra.Command { func newPageCmd() *cobra.Command {
var pageSection string
var complete bool
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "page <title>", Use: "page <title>",
Short: "Fetch and display a wiki page", Short: "Fetch and display a wiki page",
Long: `Fetches a wiki page and renders its table of contents by default. Long: `Fetches a wiki page and renders it as markdown.
Use --section to get a specific section, or --complete for the full page.
Examples: Examples:
rsw osrs page "Dragon scimitar" rsw osrs page "Dragon scimitar"
rsw osrs page "Dragon scimitar" --section "Combat styles" rsw osrs page "Mining"
rsw osrs page "Mining" --complete rsw rs3 page "Archaeology"`,
rsw rs3 page "Mining" --section "Training"`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
title := args[0] title := args[0]
@@ -44,63 +38,17 @@ Examples:
return fmt.Errorf("failed to fetch page: %w", err) return fmt.Errorf("failed to fetch page: %w", err)
} }
if pageSection != "" {
body := htmlconv.ExtractSection(page.HTML, pageSection)
if body == "" {
sections := htmlconv.ListSections(page.HTML)
return fmt.Errorf("section %q not found. Available sections: %s",
pageSection, formatSectionNames(sections))
}
md := render.New()
md.H1(page.Title)
md.Line(body)
fmt.Print(md.String())
return nil
}
md := render.New() md := render.New()
md.H1(page.Title) md.H1(page.Title)
md.Line(htmlconv.Convert(page.HTML))
sections := htmlconv.ListSections(page.HTML)
if len(sections) > 0 {
md.H2("Sections")
for _, s := range sections {
indent := ""
if s.Level == 3 {
indent = " "
} else if s.Level >= 4 {
indent = " "
}
md.Line(fmt.Sprintf("%s- %s", indent, s.Name))
}
md.Newline()
md.HR()
}
if complete {
md.Line(htmlconv.Convert(page.HTML))
} else {
md.Line("Use --section <name> to fetch a specific section, or --complete for the full page.")
}
fmt.Print(md.String()) fmt.Print(md.String())
return nil return nil
}, },
} }
cmd.Flags().StringVar(&pageSection, "section", "", "Fetch only the named section")
cmd.Flags().BoolVar(&complete, "complete", false, "Fetch the complete page content (default shows TOC only)")
return cmd return cmd
} }
func formatSectionNames(sections []htmlconv.SectionInfo) string {
names := make([]string, len(sections))
for i, s := range sections {
names[i] = s.Name
}
return strings.Join(names, ", ")
}
func init() { func init() {
RegisterCommand(newPageCmd) RegisterCommand(newPageCmd)
} }
+4 -10
View File
@@ -37,14 +37,9 @@ The first argument is always the game: `osrs` or `rs3`.
Full-text search across wiki pages. Returns ranked titles with snippets. Full-text search across wiki pages. Returns ranked titles with snippets.
Use this to find the right page name before fetching details. Use this to find the right page name before fetching details.
### rsw <game> page <title> [--section <name>] [--complete] ### rsw <game> page <title>
Fetch a wiki page. By default, returns only the table of contents (section list) Fetch a wiki page and return its full content as markdown.
to conserve context. Use `--section` to fetch a specific section (e.g., "Drops", Use `--raw` for raw wikitext instead.
"Strategy", "Requirements"). Use `--complete` for the full page content.
Use `--raw` for raw wikitext.
**Recommended workflow:** First call `page` (no flags) to see available sections,
then call `page --section <name>` to fetch only what you need.
### rsw <game> item <name> [--ironman] ### rsw <game> item <name> [--ironman]
The workhorse for "where do I find X" questions. Returns: The workhorse for "where do I find X" questions. Returns:
@@ -92,8 +87,7 @@ When a user asks a RuneScape question, think about which command(s) to combine:
`rsw osrs price "abyssal whip"` `rsw osrs price "abyssal whip"`
**"What's a good money maker at 80 combat?"** **"What's a good money maker at 80 combat?"**
`rsw osrs search "money making"` → then `rsw osrs page "Money making guide"` (TOC) `rsw osrs search "money making"` → then `rsw osrs page "Money making guide"`
→ then `rsw osrs page "Money making guide" --section "Combat"` for relevant section
### Inferring the game ### Inferring the game