diff --git a/cmd/aiven_cmd.go b/cmd/aiven_cmd.go index 6ab98c2a..cf1551a2 100644 --- a/cmd/aiven_cmd.go +++ b/cmd/aiven_cmd.go @@ -16,8 +16,10 @@ const ( var aivenCommand = &cobra.Command{ Use: "aiven [command] [args] [flags]", - Short: "Create a aivenApplication to your cluster", - Long: `This command will apply a aivenApplication based on information given and avienator will create a set of credentials`, + Short: "Create a protected & time-limited aivenApplication", + Long: `This command will apply a aivenApplication based on information given and aivenator creates a set of credentials`, + Example: `nais-cli aiven username namespace | nais-cli aiven username namespace -p nav-dev | +nais-cli aiven username namespace -e 10 | nais-cli aiven username namespace -s some-secret-name`, RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 2 { diff --git a/cmd/get_cmd.go b/cmd/get_cmd.go index 61af8c9d..733e2044 100644 --- a/cmd/get_cmd.go +++ b/cmd/get_cmd.go @@ -1,22 +1,23 @@ package cmd import ( - "fmt" "github.com/nais/nais-cli/cmd/helpers" "github.com/nais/nais-cli/pkg/config" "github.com/nais/nais-cli/pkg/secret" "github.com/spf13/cobra" - "os" + "log" ) var getCmd = &cobra.Command{ Use: "get [args] [flags]", - Short: "Returns the specified config format from a protected secret and generates credentials to 'current' location", + Short: "Return the preferred config format from a protected secret and generate files to location", + Example: `nais-cli aiven get secret-name namespace | nais-cli aiven get secret-name namespace -d ./config | +nais-cli aiven get secret-name namespace -c kcat | nais-cli aiven get secret-name namespace -c .env | + nais-cli aiven get secret-name namespace -c all`, Run: func(cmd *cobra.Command, args []string) { if len(args) != 2 { - fmt.Printf("%s and %s is reqired arguments", SecretNameFlag, TeamFlag) - os.Exit(1) + log.Fatalf("%s and %s is reqired arguments", SecretNameFlag, TeamFlag) } secretName := args[0] @@ -24,19 +25,16 @@ var getCmd = &cobra.Command{ configType, err := helpers.GetString(cmd, ConfigFlag, false) if err != nil { - fmt.Printf("getting %s: %s", ConfigFlag, err) - os.Exit(1) + log.Fatalf("getting %s: %s", ConfigFlag, err) } if configType != config.ENV && configType != config.ALL && configType != config.KCAT { - fmt.Printf("valid args: %s | %s | %s", config.ENV, config.KCAT, config.ALL) - os.Exit(1) + log.Fatalf("valid args: %s | %s | %s", config.ENV, config.KCAT, config.ALL) } dest, err := helpers.GetString(cmd, DestFlag, false) if err != nil { - fmt.Printf("getting %s: %s", DestFlag, err) - os.Exit(1) + log.Fatalf("getting %s: %s", DestFlag, err) } secret.ExtractAndGenerateConfig(configType, dest, secretName, team) }, diff --git a/cmd/helpers/helpers.go b/cmd/helpers/helpers.go index ad3635e3..295582a8 100644 --- a/cmd/helpers/helpers.go +++ b/cmd/helpers/helpers.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" "os" + "runtime" "strings" ) @@ -13,20 +14,17 @@ const ( ) func DefaultDestination(dest string) (string, error) { - path, err := os.Getwd() + current, err := os.Getwd() if dest == "" { - return path, nil + return current, nil } - if !strings.HasPrefix(dest, "/") { - dest = fmt.Sprintf("/%s", dest) - } - - newPath := fmt.Sprintf("%s%s", path, dest) if err != nil { return "", fmt.Errorf("could assign directory; %s", err) } + dest = system(dest) + newPath := fmt.Sprintf("%s%s", current, dest) if _, err := os.Stat(newPath); os.IsNotExist(err) { if err = os.Mkdir(newPath, os.FileMode(FilePermission)); err != nil { return "", fmt.Errorf("could not create directory; %s", err) @@ -35,6 +33,20 @@ func DefaultDestination(dest string) (string, error) { return newPath, nil } +func system(dest string) string { + if runtime.GOOS == "windows" { + if !strings.HasPrefix(dest, "\\") { + return fmt.Sprintf("\\%s", dest) + } else { + return dest + } + } + if !strings.HasPrefix(dest, "/") { + return fmt.Sprintf("/%s", dest) + } + return dest +} + func GetString(cmd *cobra.Command, flag string, required bool) (string, error) { if viper.GetString(flag) != "" { return viper.GetString(flag), nil diff --git a/cmd/root_cmd.go b/cmd/root_cmd.go index 5748f0e5..304e6e5a 100644 --- a/cmd/root_cmd.go +++ b/cmd/root_cmd.go @@ -16,9 +16,9 @@ var ( rootCmd = &cobra.Command{ Use: "nais-cli [command] [args] [flags]", - Short: "A simple nais client to generate resources for debug", + Short: "A simple NAIS client to generate resources for debug", Long: `nais-cli debug CLI. -This is a nais tool to extract secrets from cluster to quickly start debugging your nais resources.`, +This is a NAIS tool to extract secrets from cluster to quickly start debugging your NAIS resources.`, } )