-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from KitsuneSemCalda/dev
feat: adding promptui config
- Loading branch information
Showing
5 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/manifoldco/promptui" | ||
) | ||
|
||
func GetUserInput(label string) (*string, error) { | ||
if label == "" { | ||
return nil, errors.New("label cannot be empty") | ||
} | ||
|
||
prompt := promptui.Prompt{ | ||
Label: label, | ||
} | ||
|
||
animeName, err := prompt.Run() | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if animeName == "" { | ||
return nil, errors.New("user input cannot be empty") | ||
} | ||
|
||
return &animeName, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
cli "Animatic/Cli" | ||
"log" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Hello World!") | ||
animeName, err := cli.GetUserInput("Enter the name of the anime you want to download") | ||
|
||
if err != nil { | ||
log.Println("Occurred an unknown error: ", err.Error()) | ||
} | ||
|
||
log.Println(*animeName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cli | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
|
||
Cli "Animatic/Cli" | ||
) | ||
|
||
type MockCli struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockCli) GetUserInput(label string) (string, error) { | ||
args := m.Called(label) | ||
return args.String(0), args.Error(1) | ||
} | ||
|
||
func TestGetUserInput_ValidInput(t *testing.T) { | ||
mockCli := new(MockCli) | ||
|
||
input := "Test Anime" | ||
label := "Anime Name" | ||
mockCli.On("GetUserInput", label).Return(input, nil) | ||
|
||
result, err := mockCli.GetUserInput(label) | ||
|
||
require.NoError(t, err) | ||
|
||
assert.Equal(t, input, result) | ||
} | ||
|
||
func TestGetUserInput(t *testing.T) { | ||
t.Run("empty label", func(t *testing.T) { | ||
label := "" | ||
|
||
_, err := Cli.GetUserInput(label) | ||
|
||
assert.Error(t, err) | ||
}) | ||
|
||
t.Run("empty input", func(t *testing.T) { | ||
label := "Anime Name" | ||
|
||
_, err := Cli.GetUserInput(label) | ||
|
||
assert.Error(t, err) | ||
}) | ||
} |