Merge pull request '[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/cli/RFC.md fully. Find ONE feature ...' (#45) from agent/read---spec-code-core-go-cli-rfc-md-full into dev
Some checks are pending
Security Scan / security (push) Waiting to run
Some checks are pending
Security Scan / security (push) Waiting to run
This commit is contained in:
commit
55a665212f
2 changed files with 40 additions and 0 deletions
|
|
@ -9,6 +9,10 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var startHelpServer = func(catalog *gohelp.Catalog, addr string) error {
|
||||
return gohelp.NewServer(catalog, addr).ListenAndServe()
|
||||
}
|
||||
|
||||
func AddHelpCommands(root *cli.Command) {
|
||||
var searchQuery string
|
||||
|
||||
|
|
@ -37,6 +41,18 @@ func AddHelpCommands(root *cli.Command) {
|
|||
},
|
||||
}
|
||||
|
||||
var serveAddr string
|
||||
serveCmd := &cli.Command{
|
||||
Use: "serve",
|
||||
Short: "Serve help documentation over HTTP",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cli.Command, args []string) error {
|
||||
return startHelpServer(gohelp.DefaultCatalog(), serveAddr)
|
||||
},
|
||||
}
|
||||
serveCmd.Flags().StringVar(&serveAddr, "addr", ":8080", "HTTP listen address")
|
||||
|
||||
helpCmd.AddCommand(serveCmd)
|
||||
helpCmd.Flags().StringVarP(&searchQuery, "search", "s", "", "Search help topics")
|
||||
root.AddCommand(helpCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,30 @@ func TestAddHelpCommands_Good(t *testing.T) {
|
|||
assert.Contains(t, out, topics[0].ID)
|
||||
}
|
||||
|
||||
func TestAddHelpCommands_Good_Serve(t *testing.T) {
|
||||
root := &cli.Command{Use: "core"}
|
||||
AddHelpCommands(root)
|
||||
|
||||
cmd, _, err := root.Find([]string{"help", "serve"})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, cmd)
|
||||
|
||||
oldStart := startHelpServer
|
||||
defer func() { startHelpServer = oldStart }()
|
||||
|
||||
var gotAddr string
|
||||
startHelpServer = func(catalog *gohelp.Catalog, addr string) error {
|
||||
require.NotNil(t, catalog)
|
||||
gotAddr = addr
|
||||
return nil
|
||||
}
|
||||
|
||||
require.NoError(t, cmd.Flags().Set("addr", "127.0.0.1:9090"))
|
||||
err = cmd.RunE(cmd, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "127.0.0.1:9090", gotAddr)
|
||||
}
|
||||
|
||||
func TestRenderSearchResults_Good(t *testing.T) {
|
||||
out := captureOutput(t, func() {
|
||||
err := renderSearchResults([]*gohelp.SearchResult{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue