package cmd import ( "fmt" "os" "github.com/spf13/cobra" ) var ( ironman bool raw bool game string ) var rootCmd = &cobra.Command{ Use: "rsw ", Short: "RuneScape Wiki CLI — query the RS3 and OSRS wikis from your terminal", Long: `rsw is a command-line tool for querying the RuneScape Wiki. It supports both RS3 (runescape.wiki) and Old School RuneScape (oldschool.runescape.wiki). The first argument must be the game: "osrs" or "rs3". Examples: rsw osrs item "dragon scimitar" --ironman rsw rs3 quest "Plague's End" rsw osrs skill mining --level 50-70 --ironman rsw rs3 price "blue partyhat"`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if game != "osrs" && game != "rs3" { return fmt.Errorf("game must be 'osrs' or 'rs3', got %q", game) } return nil }, } func Execute() error { wireCommands() return rootCmd.Execute() } func init() { // Game is set by the wrapper commands, not directly by the user. // See game.go for how osrs/rs3 subcommands inject this. rootCmd.PersistentFlags().BoolVarP(&ironman, "ironman", "i", false, "Ironman mode: emphasize self-sufficient acquisition, hide GE prices") rootCmd.PersistentFlags().BoolVar(&raw, "raw", false, "Output raw wikitext instead of rendered markdown") // Suppress the default completion command rootCmd.CompletionOptions.DisableDefaultCmd = true } // GameBaseURL returns the MediaWiki API base URL for the selected game. func GameBaseURL() string { switch game { case "osrs": return "https://oldschool.runescape.wiki/api.php" case "rs3": return "https://runescape.wiki/api.php" default: fmt.Fprintf(os.Stderr, "invalid game %q\n", game) os.Exit(1) return "" } } // GamePriceBaseURL returns the real-time price API base URL. // Only valid for OSRS; RS3 uses a separate client (prices.RS3Client). func GamePriceBaseURL() string { switch game { case "osrs": return "https://prices.runescape.wiki/api/v1/osrs" default: return "" } } // Game returns the current game selection. func Game() string { return game } // Ironman returns whether ironman mode is active. func Ironman() bool { return ironman } // Raw returns whether raw output mode is active. func Raw() bool { return raw }