// Command nyro is the unified gateway CLI: `nyro proxy` (data plane), // `nyro serve` (control plane), and `nyro tool` (`ca` and `migrate` operations). package main import ( "fmt" "os" "github.com/spf13/cobra" "github.com/nyroway/nyro/go/cmd/proxy" "github.com/nyroway/nyro/go/cmd/resource" "github.com/nyroway/nyro/go/cmd/server" "github.com/nyroway/nyro/go/cmd/tool" "github.com/nyroway/nyro/go/internal/envflag" "github.com/nyroway/nyro/go/internal/version" ) // newRootCmd builds the root cobra command. Extracted from main so tests can // inspect its subcommand/flag shape without calling Execute or os.Exit. func newRootCmd() *cobra.Command { root := &cobra.Command{ Use: "nyro", Short: "Nyro AI gateway", } // nyro is not meant to be introspected via shell-completion scripts today; // disable cobra's auto-added `completion` subcommand rather than ship an // unmaintained surface. root.CompletionOptions.DisableDefaultCmd = true // Give every subcommand flag an environment-variable layer with precedence // explicit flag > env > default. Bind runs (as the inherited PersistentPreRunE) // for whichever leaf command executes; Decorate advertises each flag's env // var in --help. Both derive NYRO__ names from the command path, // so no subcommand code needs to know about env binding. root.PersistentPreRunE = envflag.Bind root.AddCommand(proxy.NewCmd()) root.AddCommand(server.NewCmd()) root.AddCommand(tool.NewCmd()) root.AddCommand(newVersionCmd()) root.AddCommand(resource.ProviderCmd()) root.AddCommand(resource.ModelCmd()) envflag.Decorate(root) return root } func newVersionCmd() *cobra.Command { return &cobra.Command{ Use: "version", Short: "Print version information", RunE: func(cmd *cobra.Command, _ []string) error { _, err := fmt.Fprintf(cmd.OutOrStdout(), "nyro version %s\n", version.Version) return err }, } } func main() { if err := newRootCmd().Execute(); err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } }