package main import ( "fmt" "os" "github.com/spf13/cobra" "go.uber.org/fx" "gopkg.in/yaml.v3" "iop/apps/node/internal/bootstrap" "iop/packages/config" "iop/packages/version" ) var cfgFile string func main() { if err := rootCmd().Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func rootCmd() *cobra.Command { root := &cobra.Command{ Use: "iop-node", Short: "IOP Node Agent — runs inference adapters on this device", } root.PersistentFlags().StringVarP(&cfgFile, "config", "c", "configs/node.yaml", "config file path") root.AddCommand(serveCmd(), versionCmd(), configCmd()) return root } func serveCmd() *cobra.Command { return &cobra.Command{ Use: "serve", Short: "Start the IOP node (connects to edge)", RunE: func(cmd *cobra.Command, _ []string) error { cfg, err := config.Load(cfgFile) if err != nil { return fmt.Errorf("load config: %w", err) } app := fx.New(bootstrap.Module(cfg)) app.Run() return nil }, } } func versionCmd() *cobra.Command { return &cobra.Command{ Use: "version", Short: "Print IOP node version", Run: func(_ *cobra.Command, _ []string) { fmt.Println(version.Version) }, } } func configCmd() *cobra.Command { cfgGroup := &cobra.Command{ Use: "config", Short: "Config management commands", } printCmd := &cobra.Command{ Use: "print", Short: "Print the resolved configuration", RunE: func(_ *cobra.Command, _ []string) error { cfg, err := config.Load(cfgFile) if err != nil { return fmt.Errorf("load config: %w", err) } enc := yaml.NewEncoder(os.Stdout) enc.SetIndent(2) return enc.Encode(cfg) }, } cfgGroup.AddCommand(printCmd) return cfgGroup }