added image info cmd & other chager
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) AddFileCmds() {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "file",
|
||||
Short: "File operation",
|
||||
}
|
||||
// PutFile
|
||||
var putFileCmd = &cobra.Command{
|
||||
Use: "put",
|
||||
Short: "Put file to storage",
|
||||
Run: util.PutFile,
|
||||
}
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Username, "username", "u", "", "Username")
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Password, "password", "p", "", "Password")
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Source, "src", "s", "", "Source path")
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Dest, "dest", "d", "", "Desctination path")
|
||||
|
||||
subCmd.AddCommand(putFileCmd)
|
||||
|
||||
// GetFile
|
||||
var getFileCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "Get file from storage",
|
||||
Run: util.GetFile,
|
||||
}
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Username, "username", "u", "", "Username")
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Password, "password", "p", "", "Password")
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Source, "src", "s", "", "Source path")
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Dest, "dest", "d", "", "Desctination path")
|
||||
|
||||
subCmd.AddCommand(getFileCmd)
|
||||
|
||||
// FileExists
|
||||
var fileExistsCmd = &cobra.Command{
|
||||
Use: "exist",
|
||||
Short: "Check file into storage",
|
||||
Run: util.FileExists,
|
||||
}
|
||||
fileExistsCmd.Flags().StringVarP(&util.fileExistsParams.Username, "username", "u", "", "Username")
|
||||
fileExistsCmd.Flags().StringVarP(&util.fileExistsParams.Password, "password", "p", "", "Password")
|
||||
fileExistsCmd.Flags().StringVarP(&util.fileExistsParams.Filepath, "path", "d", "", "File path")
|
||||
|
||||
subCmd.AddCommand(fileExistsCmd)
|
||||
|
||||
// FileExists
|
||||
var deleteFileCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete file in storage",
|
||||
Run: util.DeleteFile,
|
||||
}
|
||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Username, "username", "u", "", "Username")
|
||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Password, "password", "p", "", "Password")
|
||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Filepath, "path", "d", "", "File path")
|
||||
|
||||
subCmd.AddCommand(deleteFileCmd)
|
||||
|
||||
util.rootCmd.AddCommand(subCmd)
|
||||
}
|
||||
|
||||
type FileUtil struct {
|
||||
fileExistsParams FileExistsParams
|
||||
putFileParams PutFileParams
|
||||
getFileParams GetFileParams
|
||||
deleteFileParams DeleteFileParams
|
||||
}
|
||||
|
||||
// File exists
|
||||
type FileExistsParams struct {
|
||||
Filepath string
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (util *Util) FileExists(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Put file
|
||||
type PutFileParams struct {
|
||||
Source string
|
||||
Dest string
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (util *FileUtil) PutFile(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Get file
|
||||
type GetFileParams struct {
|
||||
Source string
|
||||
Dest string
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (util *FileUtil) GetFile(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Delete file
|
||||
type DeleteFileParams struct {
|
||||
Filepath string
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (util *FileUtil) DeleteFile(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
+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