Skip to content

Commit

Permalink
Merge pull request #4 from KitsuneSemCalda/dev
Browse files Browse the repository at this point in the history
feat: adding promptui config
  • Loading branch information
KitsuneSemCalda authored Mar 29, 2024
2 parents df9c601 + 9994a23 commit 7c4ce8c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
29 changes: 29 additions & 0 deletions Cli/promptui.go
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
}
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ module Animatic

go 1.22.1

require github.com/stretchr/testify v1.9.0
require (
github.com/manifoldco/promptui v0.9.0
github.com/stretchr/testify v1.9.0
)

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
11 changes: 9 additions & 2 deletions main.go
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)
}
52 changes: 52 additions & 0 deletions tests/cli/promptui_test.go
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)
})
}

0 comments on commit 7c4ce8c

Please sign in to comment.