Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete flags #107

Merged
merged 14 commits into from
Sep 26, 2024
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ push:
lint: bootstrap
golangci-lint run --max-same-issues 0

install:
go build ./cli/rx/
mv rx $$(go env GOPATH)/bin/rx

HAS_SWAGGER := $(shell command -v swagger;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
HAS_GORELEASER := $(shell command -v goreleaser;)
Expand Down
9 changes: 5 additions & 4 deletions cmd/createApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/equinor/radix-cli/generated-client/client/platform"
"github.com/equinor/radix-cli/generated-client/models"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)
Expand All @@ -35,7 +36,7 @@ var createApplicationCmd = &cobra.Command{
Long: "Creates a Radix application in the cluster",
Example: `rx create application --application your-application-name --repository https://github.com/your-repository --config-branch main --ad-groups abcdef-1234-5678-9aaa-abcdefgf --reader-ad-groups=23456789--9123-4567-8901-23456701 --shared-secret someSecretPhrase12345 --acknowledge-warnings --configuration-item "YOUR PROJECT CONFIG ITEM" --context playground`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}
Expand All @@ -51,7 +52,7 @@ var createApplicationCmd = &cobra.Command{
return err
}

if appName == nil || *appName == "" || repository == "" || configBranch == "" || configurationItem == "" {
if appName == "" || repository == "" || configBranch == "" || configurationItem == "" {
return errors.New("application name, repository, configuration item and config branch are required fields")
}

Expand All @@ -67,7 +68,7 @@ var createApplicationCmd = &cobra.Command{
AdGroups: adGroups,
ConfigBranch: &configBranch,
ConfigurationItem: configurationItem,
Name: appName,
Name: &appName,
RadixConfigFullName: configFile,
ReaderAdGroups: readerAdGroups,
Repository: &repository,
Expand Down Expand Up @@ -98,7 +99,7 @@ var createApplicationCmd = &cobra.Command{

}
deployKeyAndSecretParams := application.NewGetDeployKeyAndSecretParams()
deployKeyAndSecretParams.SetAppName(*appName)
deployKeyAndSecretParams.SetAppName(appName)
getRadixRegistrationNoAccessErrorCount := 3
getRadixRegistrationNoAccessErrorPause := 2 * time.Second
for {
Expand Down
11 changes: 7 additions & 4 deletions cmd/createApplyConfigPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"github.com/equinor/radix-cli/generated-client/client/application"
"github.com/equinor/radix-cli/generated-client/models"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/equinor/radix-cli/pkg/utils/completion"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -37,7 +39,7 @@ Currently applied changes in properties DNS alias, build secrets, create new or
rx create job apply-config -a radix-test`,
RunE: func(cmd *cobra.Command, args []string) error {
var errs []error
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
errs = append(errs, err)
}
Expand All @@ -52,7 +54,7 @@ Currently applied changes in properties DNS alias, build secrets, create new or
if len(errs) > 0 {
return errors.Join(errs...)
}
if appName == nil || *appName == "" {
if appName == "" {
return errors.New("application name is required")
}

Expand All @@ -64,7 +66,7 @@ Currently applied changes in properties DNS alias, build secrets, create new or
}

triggerPipelineParams := application.NewTriggerPipelineApplyConfigParams()
triggerPipelineParams.SetAppName(*appName)
triggerPipelineParams.SetAppName(appName)
parametersApplyConfig := models.PipelineParametersApplyConfig{
TriggeredBy: triggeredByUser,
}
Expand All @@ -80,7 +82,7 @@ Currently applied changes in properties DNS alias, build secrets, create new or
if !follow {
return nil
}
return getLogsJob(cmd, apiClient, *appName, jobName)
return getLogsJob(cmd, apiClient, appName, jobName)
},
}

Expand All @@ -89,5 +91,6 @@ func init() {
createApplyConfigPipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to apply-config")
createApplyConfigPipelineJobCmd.Flags().StringP(flagnames.User, "u", "", "The user who triggered the apply-config")
createApplyConfigPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow applyConfig")
_ = createApplyConfigPipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
setContextSpecificPersistentFlags(createApplyConfigPipelineJobCmd)
}
11 changes: 7 additions & 4 deletions cmd/createBuildDeployPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package cmd
import (
"errors"

"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/model"
"github.com/equinor/radix-cli/pkg/utils/completion"
log "github.com/sirupsen/logrus"

"github.com/equinor/radix-cli/generated-client/client/application"
Expand All @@ -35,7 +37,7 @@ var createBuildDeployApplicationCmd = &cobra.Command{
Short: "Will trigger build-deploy of a Radix application",
Long: `Triggers build-deploy of Radix application, if branch to environment map exists for the branch in the Radix config`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}
Expand All @@ -44,7 +46,7 @@ var createBuildDeployApplicationCmd = &cobra.Command{
commitID, _ := cmd.Flags().GetString(flagnames.CommitID)
follow, _ := cmd.Flags().GetBool(flagnames.Follow)

if appName == nil || *appName == "" || branch == "" {
if appName == "" || branch == "" {
return errors.New("application name and branch are required")
}
cmd.SilenceUsage = true
Expand All @@ -55,7 +57,7 @@ var createBuildDeployApplicationCmd = &cobra.Command{
}

triggerPipelineParams := application.NewTriggerPipelineBuildDeployParams()
triggerPipelineParams.SetAppName(*appName)
triggerPipelineParams.SetAppName(appName)
triggerPipelineParams.SetPipelineParametersBuild(&models.PipelineParametersBuild{
Branch: branch,
CommitID: commitID,
Expand All @@ -72,7 +74,7 @@ var createBuildDeployApplicationCmd = &cobra.Command{
if !follow {
return nil
}
return getLogsJob(cmd, apiClient, *appName, jobName)
return getLogsJob(cmd, apiClient, appName, jobName)
},
}

Expand All @@ -84,5 +86,6 @@ func init() {
createBuildDeployApplicationCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow build-deploy")
createBuildDeployApplicationCmd.Flags().Var(&overrideUseBuildCache, flagnames.UseBuildCache, "Optional. Overrides configured or default useBuildCache option. It is applicable when the useBuildKit option is set as true.")

_ = createBuildDeployApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
setContextSpecificPersistentFlags(createBuildDeployApplicationCmd)
}
15 changes: 10 additions & 5 deletions cmd/createDeployPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"fmt"
"regexp"

"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/utils/completion"
log "github.com/sirupsen/logrus"

"github.com/equinor/radix-cli/generated-client/client/application"
Expand Down Expand Up @@ -48,7 +50,7 @@ var createDeployPipelineJobCmd = &cobra.Command{
rx create job deploy -a radix-test -e dev --component web-app --component api-server`,
RunE: func(cmd *cobra.Command, args []string) error {
var errs []error
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
errs = append(errs, err)
}
Expand All @@ -71,7 +73,7 @@ var createDeployPipelineJobCmd = &cobra.Command{
if len(errs) > 0 {
return errors.Join(errs...)
}
if appName == nil || *appName == "" || targetEnvironment == "" {
if appName == "" || targetEnvironment == "" {
return errors.New("application name and target environment are required")
}
commitID, _ := cmd.Flags().GetString(flagnames.CommitID)
Expand All @@ -92,7 +94,7 @@ var createDeployPipelineJobCmd = &cobra.Command{
}

triggerPipelineParams := application.NewTriggerPipelineDeployParams()
triggerPipelineParams.SetAppName(*appName)
triggerPipelineParams.SetAppName(appName)
parametersDeploy := models.PipelineParametersDeploy{
ToEnvironment: targetEnvironment,
ImageTagNames: imageTagNames,
Expand All @@ -112,7 +114,7 @@ var createDeployPipelineJobCmd = &cobra.Command{
if !follow {
return nil
}
return getLogsJob(cmd, apiClient, *appName, jobName)
return getLogsJob(cmd, apiClient, appName, jobName)
},
}

Expand All @@ -137,7 +139,10 @@ func init() {
createDeployPipelineJobCmd.Flags().StringP(flagnames.User, "u", "", "The user who triggered the deploy")
createDeployPipelineJobCmd.Flags().StringToStringP(flagnames.ImageTagName, "t", map[string]string{}, "Image tag name for a component: component-name=tag-name. Multiple pairs can be specified.")
createDeployPipelineJobCmd.Flags().StringP(flagnames.CommitID, "i", "", "An optional 40 character commit id to tag the new pipeline job")
createDeployPipelineJobCmd.Flags().StringSlice(flagnames.Component, []string{}, "Optional component to deploy, when only specific component need to be deployed. Multiple components can be specified.")
createDeployPipelineJobCmd.Flags().StringSliceP(flagnames.Component, "n", []string{}, "Optional component to deploy, when only specific component need to be deployed. Multiple components can be specified.")
createDeployPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow deploy")
_ = createDeployPipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
_ = createDeployPipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Environment, completion.EnvironmentCompletion)
_ = createDeployPipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Component, completion.ComponentCompletion)
setContextSpecificPersistentFlags(createDeployPipelineJobCmd)
}
10 changes: 7 additions & 3 deletions cmd/createEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (

"github.com/equinor/radix-cli/generated-client/client/environment"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/equinor/radix-cli/pkg/utils/completion"
"github.com/spf13/cobra"
)

Expand All @@ -29,21 +31,21 @@ var createEnvironmentCmd = &cobra.Command{
Short: "Create environment",
Long: `Creates a Radix environment for the application`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}

envName, err := cmd.Flags().GetString(flagnames.Environment)

if err != nil || appName == nil || *appName == "" {
if err != nil || appName == "" {
return errors.New("environment name and application name are required fields")
}

cmd.SilenceUsage = true

parameters := environment.NewCreateEnvironmentParams().
WithAppName(*appName).
WithAppName(appName).
WithEnvName(envName)

apiClient, err := client.GetForCommand(cmd)
Expand All @@ -60,5 +62,7 @@ func init() {
createCmd.AddCommand(createEnvironmentCmd)
createEnvironmentCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application namespace")
createEnvironmentCmd.Flags().StringP(flagnames.Environment, "e", "", "Name of the environment to create")
_ = createEnvironmentCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
_ = createEnvironmentCmd.RegisterFlagCompletionFunc(flagnames.Environment, completion.EnvironmentCompletion)
setContextSpecificPersistentFlags(createEnvironmentCmd)
}
16 changes: 11 additions & 5 deletions cmd/createPromotePipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

apiclient "github.com/equinor/radix-cli/generated-client/client"
"github.com/equinor/radix-cli/generated-client/client/environment"
"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/utils/completion"

log "github.com/sirupsen/logrus"

Expand All @@ -36,7 +38,7 @@ var createPromotePipelineJobCmd = &cobra.Command{
Short: "Will trigger promote of a Radix application",
Long: `Triggers promote of a Radix application deployment`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}
Expand All @@ -55,7 +57,7 @@ var createPromotePipelineJobCmd = &cobra.Command{
return errors.New("you cannot set use-active-deployment and specify deployment name at the same time")
}

if appName == nil || *appName == "" || fromEnvironment == "" || toEnvironment == "" {
if appName == "" || fromEnvironment == "" || toEnvironment == "" {
return errors.New("application name, from and to environments are required")
}

Expand All @@ -67,7 +69,7 @@ var createPromotePipelineJobCmd = &cobra.Command{
}

if useActiveDeployment {
d, err := getActiveDeploymentName(apiClient, *appName, fromEnvironment)
d, err := getActiveDeploymentName(apiClient, appName, fromEnvironment)
if err != nil {
return err
}
Expand All @@ -76,7 +78,7 @@ var createPromotePipelineJobCmd = &cobra.Command{
}

triggerPipelineParams := application.NewTriggerPipelinePromoteParams()
triggerPipelineParams.SetAppName(*appName)
triggerPipelineParams.SetAppName(appName)
triggerPipelineParams.SetPipelineParametersPromote(&models.PipelineParametersPromote{
DeploymentName: deploymentName,
FromEnvironment: fromEnvironment,
Expand All @@ -95,7 +97,7 @@ var createPromotePipelineJobCmd = &cobra.Command{
return nil
}

return getLogsJob(cmd, apiClient, *appName, jobName)
return getLogsJob(cmd, apiClient, appName, jobName)
},
}

Expand Down Expand Up @@ -125,5 +127,9 @@ func init() {
createPromotePipelineJobCmd.Flags().StringP(flagnames.User, "u", "", "The user who triggered the promote pipeline job")
createPromotePipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow the promote pipeline job log")
createPromotePipelineJobCmd.Flags().BoolP(flagnames.UseActiveDeployment, "", false, "Promote the active deployment")
_ = createPromotePipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
_ = createPromotePipelineJobCmd.RegisterFlagCompletionFunc(flagnames.FromEnvironment, completion.EnvironmentCompletion)
_ = createPromotePipelineJobCmd.RegisterFlagCompletionFunc(flagnames.ToEnvironment, completion.EnvironmentCompletion)
_ = createPromotePipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Deployment, completion.CreateDeploymentCompletion(flagnames.FromEnvironment, true))
setContextSpecificPersistentFlags(createPromotePipelineJobCmd)
}
11 changes: 7 additions & 4 deletions cmd/deleteApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (

"github.com/equinor/radix-cli/generated-client/client/application"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/equinor/radix-cli/pkg/utils/completion"
"github.com/spf13/cobra"
)

Expand All @@ -29,19 +31,19 @@ var deleteApplicationCmd = &cobra.Command{
Short: "Delete application",
Long: `Will delete an application from the cluster`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}

if appName == nil || *appName == "" {
if appName == "" {
return errors.New("application name is a required field")
}

cmd.SilenceUsage = true

deleteApplicationParams := application.NewDeleteApplicationParams()
deleteApplicationParams.SetAppName(*appName)
deleteApplicationParams.SetAppName(appName)

apiClient, err := client.GetForCommand(cmd)
if err != nil {
Expand All @@ -55,6 +57,7 @@ var deleteApplicationCmd = &cobra.Command{

func init() {
deleteCmd.AddCommand(deleteApplicationCmd)
deleteApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to create")
deleteApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to delete")
_ = deleteApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
setContextSpecificPersistentFlags(deleteApplicationCmd)
}
Loading
Loading