2023-09-03 23:21:40 +02:00
|
|
|
package push
|
2022-10-24 21:47:20 +03:00
|
|
|
|
|
|
|
import (
|
2023-09-12 23:47:03 +02:00
|
|
|
"log"
|
2022-10-24 21:47:20 +03:00
|
|
|
|
2023-09-03 23:21:40 +02:00
|
|
|
"github.com/google/go-containerregistry/pkg/authn"
|
2023-09-06 16:44:50 +02:00
|
|
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/command"
|
2022-10-24 21:47:20 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-09-03 23:21:40 +02:00
|
|
|
func Command(keychain authn.Keychain) *cobra.Command {
|
2023-09-12 23:47:03 +02:00
|
|
|
var options options
|
2022-10-24 21:47:20 +03:00
|
|
|
cmd := &cobra.Command{
|
2023-09-05 04:14:28 +02:00
|
|
|
Use: "push",
|
2023-09-06 16:44:50 +02:00
|
|
|
Short: command.FormatDescription(true, websiteUrl, true, description...),
|
|
|
|
Long: command.FormatDescription(false, websiteUrl, true, description...),
|
|
|
|
Example: command.FormatExamples(examples...),
|
2023-09-12 23:47:03 +02:00
|
|
|
Args: cobra.ExactArgs(1),
|
2022-10-24 21:47:20 +03:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2023-09-12 23:47:03 +02:00
|
|
|
dir := args[0]
|
|
|
|
if err := options.validate(dir); err != nil {
|
|
|
|
return err
|
2022-10-24 21:47:20 +03:00
|
|
|
}
|
2023-09-12 23:47:03 +02:00
|
|
|
cmd.SilenceUsage = true
|
|
|
|
cmd.SilenceErrors = true
|
|
|
|
return options.execute(cmd.Context(), dir, keychain)
|
2022-10-24 21:47:20 +03:00
|
|
|
},
|
|
|
|
}
|
2023-09-12 23:47:03 +02:00
|
|
|
cmd.Flags().StringVarP(&options.imageRef, "image", "i", "", "image reference to push to or pull from")
|
|
|
|
if err := cmd.MarkFlagRequired("image"); err != nil {
|
|
|
|
log.Println("WARNING", err)
|
|
|
|
}
|
2022-10-24 21:47:20 +03:00
|
|
|
return cmd
|
|
|
|
}
|