Skip to content

Commit

Permalink
dont require migration dirs from github to run extenstion (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenlu authored Oct 19, 2023
1 parent 95f32cd commit 75c3dcd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
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
37 changes: 29 additions & 8 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,42 @@ func (i *InitActionCmd) setParams(dirs []string) error {
var err error
if i.DirPath == "" {
prompt := promptui.Select{
Label: "Choose migration directory",
Items: dirs,
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"},
Stdin: i.stdin,
}
if _, i.Driver, err = prompt.Run(); err != nil {
return err
}
switch {
case 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 len(dirs) > 0:
opts := append(dirs, "provide another path")
prompt := promptui.Select{
Label: "Choose migration directory",
Items: opts,
Stdin: i.stdin,
}
if _, i.DirPath, err = prompt.Run(); err != nil {
return err
}
}
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.DirPath, err = prompt.Run(); err != nil {
return err
}
}
}
if i.Token == "" {
prompt := promptui.Prompt{
Expand Down

0 comments on commit 75c3dcd

Please sign in to comment.