Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anshul committed Apr 6, 2024
1 parent 17daa81 commit 1cdb10d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
25 changes: 10 additions & 15 deletions cli/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,10 @@ func createGithubRepoFlow(ctx context.Context, ch *cmdutil.Helper, localGitPath
// Emit success telemetry
ch.Telemetry(ctx).RecordBehavioralLegacy(activity.BehavioralEventGithubConnectedSuccess)

ch.PrintfBold(`No git remote was found.
Rill projects deploy continuously when you push changes to Github.
Therefore, your project must be on Github before you deploy it to Rill.
`)

ch.Print(`
You can continue here and Rill can create a Github Repository for you or
you can exit the command and create a repository manually.
`)
ch.Print("No git remote was found.\n")
ch.Print("Rill projects deploy continuously when you push changes to Github.\n")
ch.Print("Therefore, your project must be on Github before you deploy it to Rill.\n")
ch.Print("You can continue here and Rill can create a Github Repository for you or you can exit the command and create a repository manually.\n\n")
if !cmdutil.ConfirmPrompt("Do you want to continue?", "", true) {
ch.PrintfBold(githubSetupMsg)
return nil
Expand All @@ -453,7 +446,6 @@ you can exit the command and create a repository manually.
if len(pollRes.Organizations) > 0 {
repoOwners := []string{pollRes.Account}
repoOwners = append(repoOwners, pollRes.Organizations...)
ch.Print("\nYou also have access to organization(s)\n\n")
repoOwner = cmdutil.SelectPrompt("Select Github account", repoOwners, pollRes.Account)
}
// create and verify
Expand All @@ -462,7 +454,7 @@ you can exit the command and create a repository manually.
return err
}

printer.ColorGreenBold.Printf("\nRepository %q created successfully\n\n", *githubRepository.Name)
printer.ColorGreenBold.Printf("\nSuccessfully created repository on %q\n\n", *githubRepository.HTMLURL)
ch.Print("Pushing local project to Github\n\n")
// init git repo
repo, err := git.PlainInit(localGitPath, false)
Expand Down Expand Up @@ -505,7 +497,7 @@ you can exit the command and create a repository manually.
return fmt.Errorf("failed to push to remote %q : %w", *githubRepository.HTMLURL, err)
}

ch.Print("Local changes pushed to remote\n\n")
ch.Print("Successfully pushed your local project to Github\n\n")
return nil
}
}
Expand Down Expand Up @@ -537,7 +529,10 @@ func createGithubRepository(ctx context.Context, ch *cmdutil.Helper, pollRes *ad
}

ch.Printf("Repository name %q is already taken\n", repoName)
repoName = cmdutil.InputPrompt("Please provide alternate name", "")
repoName, err = cmdutil.InputPrompt("Please provide alternate name", "")
if err != nil {
return nil, err
}
}
if err != nil {
return nil, fmt.Errorf("failed to create repository: %w", err)
Expand Down
6 changes: 5 additions & 1 deletion cli/cmd/org/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
if !force {
fmt.Printf("Warn: Deleting the org %q will remove all metadata associated with the org\n", name)
msg := fmt.Sprintf("Type %q to confirm deletion", name)
org := cmdutil.InputPrompt(msg, "")
org, err := cmdutil.InputPrompt(msg, "")
if err != nil {
return err
}

if org != name {
return fmt.Errorf("Entered incorrect name: %q, expected value is %q", org, name)
}
Expand Down
5 changes: 4 additions & 1 deletion cli/cmd/org/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ func EditCmd(ch *cmdutil.Helper) *cobra.Command {
}

if promptFlagValues {
description := cmdutil.InputPrompt("Enter the description", org.Description)
description, err = cmdutil.InputPrompt("Enter the description", org.Description)
if err != nil {
return err
}
req.Description = &description
}

Expand Down
6 changes: 5 additions & 1 deletion cli/cmd/project/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
ch.PrintfWarn("Warn: Deleting the project %q will remove all metadata associated with the project\n", name)

msg := fmt.Sprintf("Type %q to confirm deletion", name)
project := cmdutil.InputPrompt(msg, "")
project, err := cmdutil.InputPrompt(msg, "")
if err != nil {
return err
}

if project != name {
return fmt.Errorf("Entered incorrect name : %q, expected value is %q", project, name)
}
Expand Down
10 changes: 8 additions & 2 deletions cli/cmd/project/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ func EditCmd(ch *cmdutil.Helper) *cobra.Command {
}
proj := resp.Project

description = cmdutil.InputPrompt("Enter the description", proj.Description)
description, err = cmdutil.InputPrompt("Enter the description", proj.Description)
if err != nil {
return err
}
req.Description = &description

prodBranch = cmdutil.InputPrompt("Enter the production branch", proj.ProdBranch)
prodBranch, err = cmdutil.InputPrompt("Enter the production branch", proj.ProdBranch)
if err != nil {
return err
}
req.ProdBranch = &prodBranch

public = cmdutil.ConfirmPrompt("Make project public", "", proj.Public)
Expand Down
12 changes: 8 additions & 4 deletions cli/pkg/cmdutil/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ func ConfirmPrompt(msg, help string, def bool) bool {
return result
}

func InputPrompt(msg, def string) string {
func InputPrompt(msg, def string) (string, error) {
prompt := &survey.Input{
Message: msg,
Default: def,
}
result := def
if err := survey.AskOne(prompt, &result); err != nil {
fmt.Printf("Prompt failed %v\n", err)
os.Exit(1)
return "", err
}
return strings.TrimSpace(result)
return strings.TrimSpace(result), nil
}

func StringPromptIfEmpty(input *string, msg string) {
Expand Down Expand Up @@ -109,7 +109,11 @@ func SetFlagsByInputPrompts(cmd cobra.Command, flags ...string) error {

val = fmt.Sprintf("%t", public)
default:
val = InputPrompt(fmt.Sprintf("Enter the %s", f.Usage), f.DefValue)
val, err = InputPrompt(fmt.Sprintf("Enter the %s", f.Usage), f.DefValue)
if err != nil {
fmt.Println("error while input prompt, error:", err)
return
}
}

err = f.Value.Set(val)
Expand Down

0 comments on commit 1cdb10d

Please sign in to comment.