35 lines
717 B
Go
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)
|
||
|
}
|