iop/apps/node/cmd/iop-node/main.go
toki 2d6fde0876 기능: IOP 모노레포 스캐폴드 초기 구현
apps/node 중심 구현 — TCP+JSON transport, Hexagonal Architecture,
mock/cli adapter, fx DI, SQLite 실행 이력 저장.
edge/control-plane/worker는 cobra placeholder.
유닛 테스트 및 통합 테스트 클라이언트 계획서 추가.
2026-05-02 13:20:35 +09:00

85 lines
1.7 KiB
Go

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 server",
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
}