From 5ac21806f34a7c88d2685420d53cbd585f4b4f3d Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 13 Jun 2022 19:51:47 +0530 Subject: updating episodes now --- cmd/root.go | 20 ++------------------ cmd/search.go | 39 ++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 35 deletions(-) (limited to 'cmd') diff --git a/cmd/root.go b/cmd/root.go index 9e86905..b9967b4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,21 +24,11 @@ import ( "github.com/spf13/cobra" ) -// rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "macli", - Short: "Unofficial CLI-Based MyAnimeList Client.", - Long: `Description to be added later. -Help: - Even I don't know how to use it as of now... -`, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + Short: "macli - Unofficial CLI-Based MyAnimeList Client.", } -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { @@ -47,11 +37,5 @@ func Execute() { } func init() { - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.PersistentFlags().BoolP("manga", "m", false, "Use Manga Mode.") } diff --git a/cmd/search.go b/cmd/search.go index 8dff6bf..2496e17 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -22,9 +22,9 @@ import ( "github.com/spf13/cobra" "github.com/MikunoNaka/macli/ui" "strings" + "fmt" ) -// searchCmd represents the search command var searchCmd = &cobra.Command { Use: "search", Short: "Search for an anime.", @@ -34,26 +34,31 @@ var searchCmd = &cobra.Command { Run: func(cmd *cobra.Command, args []string) { // 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.") + mangaMode, _ := cmd.Flags().GetBool("manga") + + if mangaMode { + searchManga(searchInput) + } else { + searchAnime(searchInput) } - animeId := ui.SearchAndGetID("Select Anime", searchInput) - action := ui.ActionMenu() - action(animeId) }, } -func init() { - rootCmd.AddCommand(searchCmd) - - // Here you will define your flags and configuration settings. +func searchManga(searchInput string) { + if searchInput == "" { + searchInput = ui.TextInput("Search Manga:", "Search can't be blank.") + } + fmt.Printf("You typed in \"%s\" but macli doesn't search manga yet.\n", searchInput) +} - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // searchCmd.PersistentFlags().String("foo", "", "A help for foo") +func searchAnime(searchInput string) { + if searchInput == "" { + searchInput = ui.TextInput("Search Anime:", "Search can't be blank.") + } + animeId := ui.SearchAndGetID("Select Anime", searchInput) + ui.ActionMenu()(animeId) +} - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // searchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +func init() { + rootCmd.AddCommand(searchCmd) } -- cgit v1.2.3