From c37e75f4723f745edd54a3dcd57f3ecf2aab4c83 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 12 Jun 2022 17:57:40 +0530 Subject: reading searchString from command and using promptui as fallback --- cmd/search.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'cmd') 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) -- cgit v1.2.3