nfflow/internal/cmd/root.go
2024-03-29 18:05:09 +08:00

35 lines
717 B
Go

package cmd
import (
"fmt"
"github.com/loveuer/nfflow/internal/opt"
"github.com/loveuer/nfflow/internal/srv"
"github.com/spf13/cobra"
)
var (
version bool
root = &cobra.Command{
Use: "nfflow",
Run: func(cmd *cobra.Command, args []string) {
if version {
fmt.Printf("nfflow \nVersion: %s\n", opt.Version)
}
},
}
run = &cobra.Command{
Use: "run",
Example: "nfflow run --address ':80'",
RunE: func(cmd *cobra.Command, args []string) error {
return srv.Run(cmd.Context())
},
}
)
func init() {
root.Flags().BoolVarP(&version, "version", "v", false, "print version")
run.Flags().StringVar(&opt.Cfg.Address, "address", ":80", "service listen address")
root.AddCommand(run)
}