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

dont require migration dirs from github to run extenstion #323

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ func (i *InitActionCmd) Run(ctx context.Context, client *githubClient, current r
if err != nil {
return err
}
if len(dirs) == 0 {
return errors.New("no migration directories found in the repository")
}
if err = i.setParams(dirs); err != nil {
return err
}
Expand Down
16 changes: 16 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ func TestRunInitActionCmd(t *testing.T) {
Token: "token",
},
},
{
name: "no dir path supplied, choose manual dir path",
client: createGHClient(&mockService{getContentError: &github.ErrorResponse{Message: "Not Found"}}),
cmd: &InitActionCmd{
Token: "token",
DirName: "name",
},
// enter, arrow key down, enter, `dir/migrations`, enter
prompt: "\n\x1b[B\n`dir/migrations`\n\n",
expected: &InitActionCmd{
DirPath: "`dir/migrations`",
DirName: "name",
Driver: "mysql",
Token: "token",
},
},
{
name: "no dir name supplied use cloud dir name",
client: createGHClient(&mockService{getContentError: &github.ErrorResponse{Message: "Not Found"}}),
Expand Down
31 changes: 26 additions & 5 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,41 @@ import (
func (i *InitActionCmd) setParams(dirs []string) error {
var err error
if i.DirPath == "" {
prompt := promptui.Select{
Label: "Choose driver",
Items: []string{"mysql", "postgres", "mariadb", "sqlite"},
Stdin: i.stdin,
}
if _, i.Driver, err = prompt.Run(); err != nil {
return err
}
}
switch {
case i.DirPath == "" && len(dirs) == 0:
prompt := promptui.Prompt{
Label: "Enter the path of the migration directory in your repository",
Stdin: i.stdin,
}
if i.DirPath, err = prompt.Run(); err != nil {
return err
}
case i.DirPath == "" && len(dirs) > 0:
opts := append(dirs, "provide another path")
prompt := promptui.Select{
Label: "Choose migration directory",
Items: dirs,
Items: opts,
Stdin: i.stdin,
}
if _, i.DirPath, err = prompt.Run(); err != nil {
return err
}
prompt = promptui.Select{
Label: "Choose driver",
Items: []string{"mysql", "postgres", "mariadb", "sqlite"},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move that switch into the upper if since all cases require i.DirPath to be zero.

if i.DirPath == "provide another path" {
prompt := promptui.Prompt{
Label: "Enter the path of the migration directory in your repository",
Stdin: i.stdin,
}
if _, i.Driver, err = prompt.Run(); err != nil {
if i.DirPath, err = prompt.Run(); err != nil {
return err
}
}
Expand Down
Loading