Closed ajaykarthikr closed 4 months ago
Following the example in documentation to set cli name, an error is thrown.
cmd/api/main.go:45:2: not enough arguments in call to cmd.Run have () want (*cobra.Command, []string)
main.go
package main import ( "context" "net/http" "github.com/danielgtaylor/huma/v2" "github.com/danielgtaylor/huma/v2/adapters/humachi" "github.com/danielgtaylor/huma/v2/humacli" "github.com/go-chi/chi/v5" "github.com/rs/zerolog/log" ) func main() { cli := humacli.New(func(hooks humacli.Hooks, opts *Options) { router := chi.NewMux() api := humachi.New(router, huma.DefaultConfig("My API", "1.0.0")) huma.Get(api, "/", func(ctx context.Context, input *struct { }) (*struct{ Body []byte }, error) { return &struct{ Body []byte }{Body: []byte("Hello, World!")}, nil }) server := &http.Server{ Addr: ":8080", Handler: router, } hooks.OnStart(func() { log.Info().Msgf("Server listening on %s", server.Addr) err := server.ListenAndServe() if err != nil { log.Fatal().Err(err).Msg("Failed to start server") } }) }) cmd := cli.Root() cmd.Use = "appname" cmd.Version = "1.0.1" cmd.Run() }
I think it should be cli.Run() not cmd.Run().
cli.Run()
cmd.Run()
Thanks this works, ig then documentation has to be updated appropriately.
Following the example in documentation to set cli name, an error is thrown.
main.go