Skip to content

Commit

Permalink
chore(deps): remove github.com/fatih/structs
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed May 29, 2023
1 parent 66e7491 commit a310a55
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 409 deletions.
8 changes: 0 additions & 8 deletions e2e/common/cli/offline_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ func TestKamelVersionWorksOffline(t *testing.T) {
assert.Nil(t, Kamel("version", "--kube-config", "non-existent-kubeconfig-file").Execute())
}

func TestKamelHelpTraitWorksOffline(t *testing.T) {
RegisterTestingT(t)

traitCmd := Kamel("help", "trait", "--all", "--kube-config", "non-existent-kubeconfig-file")
traitCmd.SetOut(io.Discard)
assert.Nil(t, traitCmd.Execute())
}

func TestKamelHelpOptionWorksOffline(t *testing.T) {
RegisterTestingT(t)

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/apache/camel-k/v2/pkg/kamelet/repository v0.0.0
github.com/container-tools/spectrum v0.6.17
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/fatih/structs v1.1.0
github.com/gertd/go-pluralize v0.2.1
github.com/go-logr/logr v1.2.4
github.com/google/go-containerregistry v0.13.0
Expand Down Expand Up @@ -109,7 +108,6 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/set v0.2.1 h1:nn2CaJyknWE/6txyUDGwysr3G5QC6xWB/PtVjPBbeaA=
github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
Expand Down Expand Up @@ -574,8 +572,6 @@ github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (o *bindCmdOptions) validate(cmd *cobra.Command, args []string) error {
}
catalog := trait.NewCatalog(client)

return validateTraits(catalog, o.Traits)
return validateTraits(catalog, extractTraitNames(o.Traits))
}

func (o *bindCmdOptions) run(cmd *cobra.Command, args []string) error {
Expand Down
7 changes: 0 additions & 7 deletions pkg/cmd/completion_bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/spf13/cobra"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/trait"
"github.com/apache/camel-k/v2/pkg/util/camel"
)

Expand Down Expand Up @@ -70,12 +69,6 @@ __kamel_dependency_type() {
esac
}
__kamel_traits() {
local type_list="` + strings.Join(trait.NewCatalog(nil).ComputeTraitsProperties(), " ") + `"
COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
compopt -o nospace
}
__kamel_languages() {
local type_list="js groovy kotlin java xml"
COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
Expand Down
12 changes: 0 additions & 12 deletions pkg/cmd/kit_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/trait"
"github.com/apache/camel-k/v2/pkg/util"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
)

Expand Down Expand Up @@ -89,18 +88,7 @@ func (command *kitCreateCommandOptions) run(cmd *cobra.Command, args []string) e
if err != nil {
return err
}

catalog := trait.NewCatalog(c)
tp := catalog.ComputeTraitsProperties()
for _, t := range command.Traits {
kv := strings.SplitN(t, "=", 2)

if !util.StringSliceExists(tp, kv[0]) {
fmt.Fprintln(cmd.OutOrStdout(), "Error:", t, "is not a valid trait property")
return nil
}
}

kit := v1.NewIntegrationKit(command.Namespace, args[0])
key := ctrl.ObjectKey{
Namespace: command.Namespace,
Expand Down
6 changes: 2 additions & 4 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewKamelCommand(ctx context.Context) (*cobra.Command, error) {
cmd := kamelPreAddCommandInit(&options)
addKamelSubcommands(cmd, &options)

if err := addHelpSubCommands(cmd, &options); err != nil {
if err := addHelpSubCommands(cmd); err != nil {
return cmd, err
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func addKamelSubcommands(cmd *cobra.Command, options *RootCmdOptions) {
cmd.AddCommand(cmdOnly(newCmdConfig(options)))
}

func addHelpSubCommands(cmd *cobra.Command, options *RootCmdOptions) error {
func addHelpSubCommands(cmd *cobra.Command) error {
cmd.InitDefaultHelpCmd()

var helpCmd *cobra.Command
Expand All @@ -169,8 +169,6 @@ func addHelpSubCommands(cmd *cobra.Command, options *RootCmdOptions) error {
}
helpCmd.Annotations = map[string]string{offlineCommandLabel: "true"}

helpCmd.AddCommand(cmdOnly(newTraitHelpCmd(options)))

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (o *runCmdOptions) validate() error {
}
catalog := trait.NewCatalog(client)

return validateTraits(catalog, o.Traits)
return validateTraits(catalog, extractTraitNames(o.Traits))
}

func filterBuildPropertyFiles(maybePropertyFiles []string) []string {
Expand Down
9 changes: 9 additions & 0 deletions pkg/cmd/run_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,12 @@ func generateCatalog(ctx context.Context) (*camel.RuntimeCatalog, error) {

return catalog, nil
}

func extractTraitNames(traitProps []string) []string {
traitNameProps := make([]string, len(traitProps))
for i, tp := range traitProps {
splits := strings.Split(tp, ".")
traitNameProps[i] = splits[0]
}
return traitNameProps
}
8 changes: 8 additions & 0 deletions pkg/cmd/run_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ func TestDownloadDependencyWithoutFileName(t *testing.T) {
_, err = os.Stat(path)
assert.Nil(t, err)
}

func TestExtractTraitNames(t *testing.T) {
traitProps := []string{"container.enabled=true", "no-trait.noval=1", "nothing"}
tn := extractTraitNames(traitProps)
assert.Equal(t, "container", tn[0])
assert.Equal(t, "no-trait", tn[1])
assert.Equal(t, "nothing", tn[2])
}
4 changes: 2 additions & 2 deletions pkg/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func TestRunMissingTraitFlag(t *testing.T) {
"--trait", "bogus.missing",
integrationSource)
assert.NotNil(t, err)
assert.Equal(t, "bogus.missing is not a valid trait property", err.Error())
assert.Equal(t, "trait bogus does not exist in catalog", err.Error())
assert.Len(t, runCmdOptions.Traits, 1)
assert.Equal(t, "bogus.missing", runCmdOptions.Traits[0])
}
Expand Down Expand Up @@ -668,7 +668,7 @@ func TestMissingTrait(t *testing.T) {
runCmdOptions, runCmd, _ := initializeRunCmdOptionsWithOutput(t)
output, err := test.ExecuteCommand(runCmd, cmdRun, tmpFile.Name(), "-o", "yaml", "-t", "bogus.fail=i-must-fail")
assert.Equal(t, "yaml", runCmdOptions.OutputFormat)
assert.Equal(t, "Error: bogus.fail=i-must-fail is not a valid trait property\n", output)
assert.Equal(t, "Error: trait bogus does not exist in catalog\n", output)
assert.NotNil(t, err)
}

Expand Down
Loading

0 comments on commit a310a55

Please sign in to comment.