diff options
author | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-12 17:57:40 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-12 17:57:40 +0530 |
commit | c37e75f4723f745edd54a3dcd57f3ecf2aab4c83 (patch) | |
tree | e369fde1b33cd78a647d48359e6a20e9c7c78b45 | |
parent | 1f404fdb78b9254379848086fba222f6317ea339 (diff) |
reading searchString from command and using promptui as fallback
-rw-r--r-- | cmd/search.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cmd/search.go b/cmd/search.go index 7edd9bc..8dff6bf 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -21,17 +21,23 @@ package cmd import ( "github.com/spf13/cobra" "github.com/MikunoNaka/macli/ui" + "strings" ) // searchCmd represents the search command -var searchCmd = &cobra.Command{ +var searchCmd = &cobra.Command { Use: "search", Short: "Search for an anime.", Long: ` -- help/description to be added later `, Run: func(cmd *cobra.Command, args []string) { - searchInput := ui.TextInput("Search Anime:", "Search can't be blank.") + // read searchInput from command + searchInput := strings.Join(args, " ") + // if blank, ask for input + if searchInput == "" { + searchInput = ui.TextInput("Search Anime:", "Search can't be blank.") + } animeId := ui.SearchAndGetID("Select Anime", searchInput) action := ui.ActionMenu() action(animeId) |