1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-13 11:18:47 +00:00

refactor: cli commands tests and error handling (#8367)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-09-13 11:53:19 +02:00 committed by GitHub
parent c88f8e8638
commit dc71610df7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 974 additions and 139 deletions

View file

@ -74,9 +74,9 @@ func Command() *cobra.Command {
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, policyPaths []string) (err error) {
RunE: func(cmd *cobra.Command, args []string) (err error) {
color.InitColors(removeColor)
applyCommandConfig.PolicyPaths = policyPaths
applyCommandConfig.PolicyPaths = args
rc, _, skipInvalidPolicies, responses, err := applyCommandConfig.applyCommandHelper()
if err != nil {
return err

View file

@ -1,7 +1,9 @@
package apply
import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"strings"
@ -372,3 +374,43 @@ func TestCommand(t *testing.T) {
err := cmd.Execute()
assert.NoError(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: require policy`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -15,12 +15,10 @@ import (
func RootCommand(experimental bool) *cobra.Command {
cmd := &cobra.Command{
Use: "kyverno",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "kyverno",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Help()
},

View file

@ -1,6 +1,9 @@
package commands
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -21,3 +24,46 @@ func TestRootCommandExperimental(t *testing.T) {
err := cmd.Execute()
assert.NoError(t, err)
}
func TestRootCommandWithInvalidArg(t *testing.T) {
cmd := RootCommand(false)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `
Error: unknown command "foo" for "kyverno"
Run 'kyverno --help' for usage.`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestRootCommandWithInvalidFlag(t *testing.T) {
cmd := RootCommand(false)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestRootCommandHelp(t *testing.T) {
cmd := RootCommand(false)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -12,13 +12,12 @@ import (
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "create",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},

View file

@ -1,6 +1,9 @@
package create
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "create"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -27,13 +27,12 @@ func Command() *cobra.Command {
var rules, any, all []string
var options options
cmd := &cobra.Command{
Use: "exception [name]",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.ExactArgs(1),
SilenceErrors: true,
SilenceUsage: true,
Use: "exception [name]",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
tmpl, err := template.New("exception").Parse(templates.ExceptionTemplate)
if err != nil {

View file

@ -99,3 +99,43 @@ spec:
- rule-2`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: accepts 1 arg(s), received 0`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -25,13 +25,12 @@ func Command() *cobra.Command {
var path string
var options options
cmd := &cobra.Command{
Use: "metrics-config",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "metrics-config",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
tmpl, err := template.New("metricsconfig").Funcs(sprig.HermeticTxtFuncMap()).Parse(templates.MetricsConfigTemplate)
if err != nil {

View file

@ -1,6 +1,9 @@
package metricsconfig
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "metrics-config"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -33,13 +33,12 @@ func Command() *cobra.Command {
var options options
var pass, fail, skip []string
cmd := &cobra.Command{
Use: "test",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "test",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
tmpl, err := template.New("test").Parse(templates.TestTemplate)
if err != nil {

View file

@ -1,6 +1,9 @@
package test
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "test"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -16,13 +16,12 @@ func Command() *cobra.Command {
var username string
var roles, clusterRoles, groups []string
cmd := &cobra.Command{
Use: "user-info",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "user-info",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
tmpl, err := template.New("userinfo").Parse(templates.UserInfoTemplate)
if err != nil {

View file

@ -1,6 +1,9 @@
package userinfo
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "user-info"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -15,13 +15,12 @@ func Command() *cobra.Command {
var path string
var globalValues, namespaceSelector, rules, resources []string
cmd := &cobra.Command{
Use: "values",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "values",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
tmpl, err := template.New("values").Parse(templates.ValuesTemplate)
if err != nil {

View file

@ -1,6 +1,9 @@
package values
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "values"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -10,17 +10,16 @@ import (
func Command(root *cobra.Command) *cobra.Command {
var options options
cmd := &cobra.Command{
Use: "docs",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
Use: "docs",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
if err := options.validate(root); err != nil {
return err
}
cmd.SilenceUsage = true
cmd.SilenceErrors = true
return options.execute(root)
},
}

View file

@ -1,6 +1,9 @@
package docs
import (
"bytes"
"io"
"strings"
"testing"
"github.com/spf13/cobra"
@ -21,3 +24,44 @@ func TestCommandWithoutArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command(&cobra.Command{})
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "docs"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command(&cobra.Command{})
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command(&cobra.Command{})
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -8,13 +8,12 @@ import (
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "fix",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "fix",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},

View file

@ -1,6 +1,9 @@
package fix
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "fix"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -8,17 +8,16 @@ import (
func Command() *cobra.Command {
var options options
cmd := &cobra.Command{
Use: "test [dir]...",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.MinimumNArgs(1),
Use: "test [dir]...",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.MinimumNArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args...); err != nil {
return err
}
cmd.SilenceUsage = true
cmd.SilenceErrors = true
return options.execute(cmd.OutOrStdout(), args...)
},
}

View file

@ -1,6 +1,9 @@
package test
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,43 @@ func TestCommandInvalidFileName(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: requires at least 1 arg(s), only received 0`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -10,13 +10,12 @@ import (
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "jp",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "jp",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Help()
},

View file

@ -1,6 +1,9 @@
package jp
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "jp"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -14,12 +14,11 @@ import (
func Command() *cobra.Command {
return &cobra.Command{
Use: "function [function_name]...",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
SilenceErrors: true,
SilenceUsage: true,
Use: "function [function_name]...",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
printFunctions(cmd.OutOrStdout(), args...)
},

View file

@ -1,6 +1,9 @@
package function
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -28,3 +31,30 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.NoError(t, err)
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -14,12 +14,11 @@ import (
func Command() *cobra.Command {
var files []string
cmd := &cobra.Command{
Use: "parse [-f file|expression]...",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
SilenceErrors: true,
SilenceUsage: true,
Use: "parse [-f file|expression]...",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
expressions, err := loadExpressions(cmd, args, files)
if err != nil {

View file

@ -1,6 +1,9 @@
package parse
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -13,3 +16,43 @@ func TestCommand(t *testing.T) {
err := cmd.Execute()
assert.NoError(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := "Error: SyntaxError: Incomplete expression\n\n^"
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -21,12 +21,11 @@ func Command() *cobra.Command {
var input string
var queries []string
cmd := &cobra.Command{
Use: "query [-i input] [-q query|query]...",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
SilenceErrors: true,
SilenceUsage: true,
Use: "query [-i input] [-q query|query]...",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
queries, err := loadQueries(cmd, args, queries)
if err != nil {

View file

@ -1,6 +1,9 @@
package query
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -13,3 +16,43 @@ func TestCommand(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: at least one query or input object is required`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -19,13 +19,12 @@ func Command() *cobra.Command {
registryclient.AzureKeychain,
)
cmd := &cobra.Command{
Use: "oci",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "oci",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Help()
},

View file

@ -1,6 +1,9 @@
package oci
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +23,44 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "oci"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -11,18 +11,17 @@ import (
func Command(keychain authn.Keychain) *cobra.Command {
var options options
cmd := &cobra.Command{
Use: "pull [dir]",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.ExactArgs(1),
Use: "pull [dir]",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
dir := args[0]
if err := options.validate(dir); err != nil {
return err
}
cmd.SilenceUsage = true
cmd.SilenceErrors = true
return options.execute(cmd.Context(), dir, keychain)
},
}

View file

@ -1,6 +1,9 @@
package pull
import (
"bytes"
"io"
"strings"
"testing"
"github.com/google/go-containerregistry/pkg/authn"
@ -31,3 +34,43 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command(keychain)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: accepts 1 arg(s), received 0`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command(keychain)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command(keychain)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -11,18 +11,17 @@ import (
func Command(keychain authn.Keychain) *cobra.Command {
var options options
cmd := &cobra.Command{
Use: "push",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.ExactArgs(1),
Use: "push [dir or file]",
Short: command.FormatDescription(true, websiteUrl, true, description...),
Long: command.FormatDescription(false, websiteUrl, true, description...),
Example: command.FormatExamples(examples...),
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
dir := args[0]
if err := options.validate(dir); err != nil {
return err
}
cmd.SilenceUsage = true
cmd.SilenceErrors = true
return options.execute(cmd.Context(), dir, keychain)
},
}

View file

@ -1,6 +1,9 @@
package push
import (
"bytes"
"io"
"strings"
"testing"
"github.com/google/go-containerregistry/pkg/authn"
@ -31,3 +34,43 @@ func TestCommandWithArgs(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
}
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command(keychain)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: accepts 1 arg(s), received 0`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command(keychain)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command(keychain)
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -24,11 +24,12 @@ func Command() *cobra.Command {
var fileName, gitBranch string
var registryAccess, failOnly, removeColor, detailedResults bool
cmd := &cobra.Command{
Use: "test [local folder or git repository]...",
Args: cobra.MinimumNArgs(1),
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Use: "test [local folder or git repository]...",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.MinimumNArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, dirPath []string) (err error) {
color.InitColors(removeColor)
store.SetRegistryAccess(registryAccess)

View file

@ -0,0 +1,50 @@
package test
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: requires at least 1 arg(s), only received 0`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -10,13 +10,12 @@ import (
func Command() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Use: "version",
Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
fmt.Fprintf(cmd.OutOrStdout(), "Version: %s\n", version.Version())
fmt.Fprintf(cmd.OutOrStdout(), "Time: %s\n", version.Time())

View file

@ -27,10 +27,43 @@ Git commit ID: ---`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithArgs(t *testing.T) {
func TestCommandWithInvalidArg(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
cmd.SetArgs([]string{"test"})
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"foo"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown command "foo" for "version"`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithInvalidFlag(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetErr(b)
cmd.SetArgs([]string{"--xxx"})
err := cmd.Execute()
assert.Error(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `Error: unknown flag: --xxx`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandHelp(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(string(out), cmd.Long))
}

View file

@ -12,21 +12,22 @@ import (
)
func main() {
if err := run(); err != nil {
cmd, err := setup()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}
func run() error {
func setup() (*cobra.Command, error) {
cmd := commands.RootCommand(experimental.IsEnabled())
if err := configureLogs(cmd); err != nil {
return fmt.Errorf("Failed to setup logging (%w)", err)
return nil, fmt.Errorf("Failed to setup logging (%w)", err)
}
if err := cmd.Execute(); err != nil {
return fmt.Errorf("Failed to execute command (%w)", err)
}
return nil
return cmd, nil
}
func configureLogs(cli *cobra.Command) error {

View file

@ -11,7 +11,7 @@ Push policie(s) that are included in an OCI image to OCI registry.
For more information visit https://kyverno.io/docs/kyverno-cli/#pushing
```
kyverno oci push [flags]
kyverno oci push [dir or file] [flags]
```
### Examples