working commit

This commit is contained in:
2026-02-18 23:22:46 +02:00
parent e1ca9b1b4c
commit 4a43a22c19
12 changed files with 500 additions and 92 deletions
+28 -22
View File
@@ -12,6 +12,7 @@ package main
import (
"context"
"net/url"
"os"
"path"
"strings"
"time"
@@ -44,7 +45,7 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
var subCmd = &cobra.Command{
Use: "images",
Short: "Image operation",
Short: "Image operations",
Aliases: []string{"image"},
}
subCmd.PersistentFlags().StringVarP(&util.commonImageParams.Username, "user", "u", "", "Username")
@@ -54,50 +55,38 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
// PushImage
var pushImageCmd = &cobra.Command{
Use: "push",
Use: "push filename [user:pass@]hostname[:port]/path:tag",
Short: "Push container image from local tar file into registry",
Args: cobra.ExactArgs(2),
Run: util.PushImage,
}
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Imagepath, "image", "i", "", "Remote image path")
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Filepath, "file", "f", "", "Local tar file path")
pushImageCmd.MarkFlagRequired("image")
pushImageCmd.MarkFlagRequired("file")
subCmd.AddCommand(pushImageCmd)
// ImageInfo
var imageInfoCmd = &cobra.Command{
Use: "info",
Use: "info [user:pass@]hostname[:port]/path:tag",
Short: "Show container image info",
Args: cobra.ExactArgs(1),
Run: util.ImageInfo,
}
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Imagepath, "image", "i", "", "Remote image path")
imageInfoCmd.MarkFlagRequired("image")
subCmd.AddCommand(imageInfoCmd)
// PullImage
var pullImageCmd = &cobra.Command{
Use: "pull",
Use: "pull [user:pass@]hostname[:port]/path:tag filename",
Short: "Pull container image from registry into local file",
Args: cobra.ExactArgs(2),
Run: util.PullImage,
}
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Imagepath, "image", "i", "", "Remote image path")
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Filepath, "file", "f", "", "Local file path")
pullImageCmd.MarkFlagRequired("image")
pullImageCmd.MarkFlagRequired("file")
subCmd.AddCommand(pullImageCmd)
// DeleteImage
var deleteImageCmd = &cobra.Command{
Use: "delete",
Use: "delete [user:pass@]hostname[:port]/path:tag",
Short: "Delete container image from registry",
Args: cobra.ExactArgs(1),
Run: util.DeleteImage,
}
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Imagepath, "image", "i", "", "Remote image path")
deleteImageCmd.MarkFlagRequired("image")
subCmd.AddCommand(deleteImageCmd)
return subCmd
@@ -126,6 +115,9 @@ type PushImageParams struct {
type PushImageResult struct{}
func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
util.pushImageParams.Filepath = args[0]
util.pushImageParams.Imagepath = args[1]
res, err := util.pushImage(&util.commonImageParams, &util.pushImageParams)
printResponse(res, err)
}
@@ -159,6 +151,7 @@ type ImageInfoResult struct {
}
func (util *ImageUtil) ImageInfo(cmd *cobra.Command, args []string) {
util.imageInfoParams.Imagepath = args[0]
res, err := util.imageInfo(&util.commonImageParams, &util.imageInfoParams)
printResponse(res, err)
}
@@ -190,9 +183,14 @@ type PullImageParams struct {
Filepath string
}
type PullImageResult struct{}
type PullImageResult struct {
Filepath string `yaml:"filepath"`
Size int64 `yaml:"size"`
}
func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) {
util.pullImageParams.Imagepath = args[0]
util.pullImageParams.Filepath = args[1]
res, err := util.pullImage(&util.commonImageParams, &util.pullImageParams)
printResponse(res, err)
}
@@ -214,6 +212,13 @@ func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImagePar
if err != nil {
return res, err
}
filestat, err := os.Stat(params.Filepath)
if err != nil {
return res, err
}
res.Size = filestat.Size()
res.Filepath = params.Filepath
return res, err
}
@@ -226,6 +231,7 @@ type DeleteImageResult struct {
}
func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) {
util.deleteImageParams.Imagepath = args[0]
res, err := util.deleteImage(&util.commonImageParams, &util.deleteImageParams)
printResponse(res, err)
}