From db7ed2fa3b513824b1e4a42a53e25ac0de8d5d59 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:06:43 +0200 Subject: [PATCH] Adds subcommands --- cmd/add.go | 40 ++++++++++++++++++++++++++++++++++++++++ cmd/today.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 cmd/add.go create mode 100644 cmd/today.go diff --git a/cmd/add.go b/cmd/add.go new file mode 100644 index 0000000..297a546 --- /dev/null +++ b/cmd/add.go @@ -0,0 +1,40 @@ +/* +Copyright © 2024 NAME HERE + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// addCmd represents the add command +var addCmd = &cobra.Command{ + Use: "add", + 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("add called") + }, +} + +func init() { + rootCmd.AddCommand(addCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // addCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/today.go b/cmd/today.go new file mode 100644 index 0000000..af27a57 --- /dev/null +++ b/cmd/today.go @@ -0,0 +1,42 @@ +/* +Copyright © 2024 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// todayCmd represents the today command +var todayCmd = &cobra.Command{ + Use: "today", + 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) { + dbPath := viper.GetString("path") + fmt.Println(dbPath) + fmt.Println("today called") + }, +} + +func init() { + rootCmd.AddCommand(todayCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // todayCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // todayCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +}