refactor: replace explicit fields with tag-based property system
This commit is contained in:
37
cmd/root.go
37
cmd/root.go
@@ -2,23 +2,46 @@ package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var jsonFlag bool
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "ax",
|
||||
Short: "The axolotl issue tracker",
|
||||
}
|
||||
var rootCmd = &cobra.Command{Use: "ax", Short: "The axolotl issue tracker"}
|
||||
|
||||
func Execute() {
|
||||
rootCmd.SetArgs(transformArgs(os.Args[1:]))
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVar(&jsonFlag, "json", false, "output as JSON")
|
||||
func transformArgs(args []string) []string {
|
||||
aliases := map[string]string{
|
||||
"--status": "_status",
|
||||
"--prio": "_prio",
|
||||
"--type": "_type",
|
||||
"--namespace": "_namespace",
|
||||
}
|
||||
result := []string{}
|
||||
|
||||
for i := 0; i < len(args); i++ {
|
||||
if idx := strings.Index(args[i], "="); idx != -1 {
|
||||
if prop, ok := aliases[args[i][:idx]]; ok {
|
||||
result = append(result, "--tag", prop+"::"+args[i][idx+1:])
|
||||
continue
|
||||
}
|
||||
}
|
||||
if prop, ok := aliases[args[i]]; ok && i+1 < len(args) {
|
||||
result, i = append(result, "--tag", prop+"::"+args[i+1]), i+1
|
||||
continue
|
||||
}
|
||||
result = append(result, args[i])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVar(&jsonFlag, "json", false, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user