Skip to content

Commit

Permalink
style(cli): use appropriate icons per platform
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Apr 30, 2020
1 parent 9842a0d commit c3e051e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 33 deletions.
7 changes: 7 additions & 0 deletions cli/cmd/cli_update_cmd.go → cli/cmd/cli_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

package cmd

import "github.com/AlecAivazis/survey/v2"

// promptIconsFuncs configures the prompt icons for Unix systems
var promptIconsFunc = func(icons *survey.IconSet) {
icons.Question.Text = "▸"
}

// UpdateCommand returns the command that a user should run to update the cli
// to the latest available version (unix specific command)
func (c *cliState) UpdateCommand() string {
Expand Down
7 changes: 7 additions & 0 deletions cli/cmd/cli_update_cmd_windows.go → cli/cmd/cli_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

package cmd

import "github.com/AlecAivazis/survey/v2"

// promptIconsFuncs configures the prompt icons for Windows systems
var promptIconsFunc = func(icons *survey.IconSet) {
icons.Question.Text = ">"
}

// UpdateCommand returns the command that a user should run to update the cli
// to the latest available version (windows specific command)
func (c *cliState) UpdateCommand() string {
Expand Down
35 changes: 10 additions & 25 deletions cli/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/BurntSushi/toml"
homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -89,49 +88,35 @@ func promptConfigureSetup() error {
Message: "Account: ",
Default: cli.Account,
},
Validate: func(input interface{}) error {
if str, ok := input.(string); !ok || len(str) == 0 {
return errors.New(
"The account subdomain of URL is required. (i.e. <ACCOUNT>.lacework.net)")
}
return nil
},
Validate: promptRequiredStringLen(0,
"The account subdomain of URL is required. (i.e. <ACCOUNT>.lacework.net)",
),
},
{
Name: "api_key",
Prompt: &survey.Input{
Message: "Access Key ID: ",
Default: cli.KeyID,
},
Validate: func(input interface{}) error {
if str, ok := input.(string); !ok || len(str) < 55 {
return errors.New(
"The API access key id must have more than 55 characters.")
}
return nil
},
Validate: promptRequiredStringLen(55,
"The API access key id must have more than 55 characters.",
),
},
{
Name: "api_secret",
Prompt: &survey.Input{
Message: "Secret Access Key: ",
Default: cli.Secret,
},
Validate: func(input interface{}) error {
if str, ok := input.(string); !ok || len(str) < 30 {
return errors.New(
"The API secret access key must have more than 30 characters.")
}
return nil
},
Validate: promptRequiredStringLen(30,
"The API secret access key must have more than 30 characters.",
),
},
}

newCreds := credsDetails{}
err := survey.Ask(questions, &newCreds,
survey.WithIcons(func(icons *survey.IconSet) {
icons.Question.Text = "▸"
}),
survey.WithIcons(promptIconsFunc),
)
if err != nil {
return err
Expand Down
7 changes: 2 additions & 5 deletions cli/cmd/integration_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ func createAwsConfigIntegration(lacework *api.Client) error {
}{}

err := survey.Ask(questions, &answers,
survey.WithIcons(func(icons *survey.IconSet) {
icons.Question.Text = "▸"
}),
survey.WithIcons(promptIconsFunc),
)
if err != nil {
return err
}

aws := api.NewAwsIntegration(answers.Name,
api.AwsCfgIntegration,
aws := api.NewAwsCfgIntegration(answers.Name,
api.AwsIntegrationData{
Credentials: api.AwsIntegrationCreds{
RoleArn: answers.RoleArn,
Expand Down
4 changes: 1 addition & 3 deletions cli/cmd/integration_docker_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func createDockerHubIntegration(lacework *api.Client) error {
}{}

err := survey.Ask(questions, &answers,
survey.WithIcons(func(icons *survey.IconSet) {
icons.Question.Text = "▸"
}),
survey.WithIcons(promptIconsFunc),
)
if err != nil {
return err
Expand Down
30 changes: 30 additions & 0 deletions cli/cmd/prompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Author:: Salim Afiune Maya (<[email protected]>)
// Copyright:: Copyright 2020, Lacework Inc.
// License:: Apache License, Version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package cmd

import "github.com/pkg/errors"

func promptRequiredStringLen(size int, err string) func(interface{}) error {
return func(input interface{}) error {
if str, ok := input.(string); !ok || len(str) == 0 {
return errors.New(err)
}
return nil
}
}

0 comments on commit c3e051e

Please sign in to comment.