added image info cmd & other chager
This commit is contained in:
+22
-2
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -22,6 +23,7 @@ func main() {
|
||||
|
||||
type Util struct {
|
||||
FileUtil
|
||||
ImageUtil
|
||||
rootCmd cobra.Command
|
||||
}
|
||||
|
||||
@@ -36,9 +38,10 @@ func (util *Util) Build() error {
|
||||
Short: "A brief description the command",
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
util.rootCmd = rootCmd
|
||||
rootCmd.AddCommand(util.CreateFileCmds())
|
||||
rootCmd.AddCommand(util.CreateImageCmds())
|
||||
|
||||
util.AddFileCmds()
|
||||
util.rootCmd = rootCmd
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -53,3 +56,20 @@ func (util *Util) Exec(args []string) error {
|
||||
func (util *Util) Hello(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("hello, world!")
|
||||
}
|
||||
|
||||
func printResponse(res any, err error) {
|
||||
type Response struct {
|
||||
Error bool `json:"error" yaml:"error"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Result any `json:"result,omitempty" yaml:"result,omitempty"`
|
||||
}
|
||||
resp := Response{}
|
||||
if err != nil {
|
||||
resp.Error = true
|
||||
resp.Message = err.Error()
|
||||
} else {
|
||||
resp.Result = res
|
||||
}
|
||||
respBytes, _ := yaml.Marshal(resp)
|
||||
fmt.Printf("---\n%s\n", string(respBytes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user