/
main.go
61 lines (50 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"flag"
"io"
"os"
"github.com/spf13/cobra"
fetch "github.com/13013SwagR/semver-manager/smgr/cmd/fetch"
"github.com/13013SwagR/semver-manager/smgr/internal/utils"
"k8s.io/klog/v2"
)
type fetchFlags struct {
Token string `san:"trim"`
Repository string `san:"trim"`
Owner string `san:"trim"`
Platform string `san:"trim"`
}
type config struct {
dryRun bool
}
func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "false")
flag.Set("alsologtostderr", "false")
flag.Parse()
cmd := NewRootCommand(os.Stdout)
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}
func NewRootCommand(output io.Writer) *cobra.Command {
klog.SetOutput(output)
config := config{
dryRun: false,
}
rootCmd := &cobra.Command{
Use: "smgr",
Short: "Manage Semantic Versioning compliant versions.",
Long: `Manage Semantic Versioning compliant versions and integrate with popular or registry platform to facilitate the task.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return utils.InitializeConfig(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
rootCmd.PersistentFlags().BoolVar(&config.dryRun, "dry-run", false, "Execute the command in dry-run mode")
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
rootCmd.AddCommand(fetch.NewFetchCommand(output))
return rootCmd
}