🎉 start the project
This commit is contained in:
34
internal/cmd/root.go
Normal file
34
internal/cmd/root.go
Normal file
@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
13
internal/cmd/run.go
Normal file
13
internal/cmd/run.go
Normal file
@ -0,0 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Run(ctx context.Context) {
|
||||
if err := root.ExecuteContext(ctx); err != nil {
|
||||
logrus.Debugf("cmd.Run: execute with err=%v", err)
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user