restructure and removed the completion flag

This commit is contained in:
Jan 2024-09-19 21:21:09 +02:00
parent 238e19b914
commit 17bf99c828
6 changed files with 13 additions and 128 deletions

View File

@ -1,40 +0,0 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// cityCmd represents the city command
var cityCmd = &cobra.Command{
Use: "city",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("city called")
},
}
func init() {
searchCmd.AddCommand(cityCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// cityCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// cityCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

View File

@ -10,9 +10,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// addCmd represents the add command // favCmd represents the fav command
var addCmd = &cobra.Command{ var favCmd = &cobra.Command{
Use: "add", Use: "fav",
Short: "A brief description of your command", Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example: and usage of using your command. For example:
@ -21,20 +21,20 @@ Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files This application is a tool to generate the needed files
to quickly create a Cobra application.`, to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("add called") fmt.Println("fav called")
}, },
} }
func init() { func init() {
rootCmd.AddCommand(addCmd) rootCmd.AddCommand(favCmd)
// Here you will define your flags and configuration settings. // Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command // Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.: // and all subcommands, e.g.:
// addCmd.PersistentFlags().String("foo", "", "A help for foo") // favCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command // Cobra supports local flags which will only run when this command
// is called directly, e.g.: // is called directly, e.g.:
// addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") // favCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }

View File

@ -1,34 +0,0 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// getCmd represents the get command
var getCmd = &cobra.Command{
Use: "get",
Short: "Displays your favorite Mensa meal plans.",
Long: `.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("get called")
},
}
func init() {
rootCmd.AddCommand(getCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// getCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// getCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

View File

@ -1,39 +0,0 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// mensaCmd represents the mensa command
var mensaCmd = &cobra.Command{
Use: "mensa",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("mensa called")
},
}
func init() {
searchCmd.AddCommand(mensaCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// mensaCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// mensaCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

View File

@ -43,6 +43,9 @@ func init() {
// Cobra also supports local flags, which will only run // Cobra also supports local flags, which will only run
// when this action is called directly. // when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// Disable the default help command
rootCmd.CompletionOptions.DisableDefaultCmd = true
} }
func initConfig() { func initConfig() {

View File

@ -17,13 +17,10 @@ import (
// searchCmd represents the search command // searchCmd represents the search command
var searchCmd = &cobra.Command{ var searchCmd = &cobra.Command{
Use: "search", Use: "search",
Short: "A brief description of your command", Short: "Gets a Mensa to display or add it to your favorites",
Long: `A longer description that spans multiple lines and likely contains examples Long: `This command will prompt you to select a state, city and mensa.
and usage of using your command. For example: You can then choose to display the menu or save the mensa to your favorites.`,
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
prompt := promptui.Select{ prompt := promptui.Select{
Label: "Select Day", Label: "Select Day",
@ -92,8 +89,6 @@ to quickly create a Cobra application.`,
return return
} }
fmt.Printf("You choose %q\n", result)
if result == "menu" { if result == "menu" {
data, err := internal.GetMenu(selectedCity, selectedMensa) data, err := internal.GetMenu(selectedCity, selectedMensa)
if err != nil { if err != nil {