From d597da3b649ef12d8b1dd72e350ba6cdbffd86e2 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 19 Jan 2022 15:30:30 -0600 Subject: [PATCH] Boilerplate for all operations --- cmd/archive.go | 21 +++++++-------------- cmd/config.go | 21 +++++++-------------- cmd/editor.go | 21 +++++++-------------- cmd/fuzzyparse.go | 33 +++++++++++++-------------------- cmd/i3status.go | 2 +- cmd/list.go | 2 +- cmd/mod.go | 21 +++++++-------------- cmd/rm.go | 21 +++++++-------------- cmd/root.go | 2 +- cmd/start.go | 21 +++++++-------------- cmd/status.go | 2 +- cmd/stop.go | 21 +++++++-------------- cmd/switch.go | 21 +++++++-------------- cmd/time.go | 2 +- cmd/toggle.go | 21 +++++++-------------- cmd/ui.go | 30 ++++++++---------------------- 16 files changed, 89 insertions(+), 173 deletions(-) diff --git a/cmd/archive.go b/cmd/archive.go index 1d3d852..5f6bb0e 100644 --- a/cmd/archive.go +++ b/cmd/archive.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("archive called") - }, + RunE: opArchive, } func init() { rootCmd.AddCommand(archiveCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // archiveCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // archiveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opArchive(cmd *cobra.Command, args []string) error { + fmt.Println("archive called") + return nil } diff --git a/cmd/config.go b/cmd/config.go index 0590410..1967dfb 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 brian buller */ package cmd @@ -20,21 +20,14 @@ 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("config called") - }, + RunE: opConfig, } func init() { rootCmd.AddCommand(configCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // configCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // configCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opConfig(cmd *cobra.Command, args []string) error { + fmt.Println("config called") + return nil } diff --git a/cmd/editor.go b/cmd/editor.go index 5dffd8b..71bd8c6 100644 --- a/cmd/editor.go +++ b/cmd/editor.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("editor called") - }, + RunE: opEditor, } func init() { rootCmd.AddCommand(editorCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // editorCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // editorCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opEditor(cmd *cobra.Command, args []string) error { + fmt.Println("editor called") + return nil } diff --git a/cmd/fuzzyparse.go b/cmd/fuzzyparse.go index 8f79b79..6aa8ed4 100644 --- a/cmd/fuzzyparse.go +++ b/cmd/fuzzyparse.go @@ -1,40 +1,33 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd import ( "fmt" + "time" + "git.bullercodeworks.com/brian/gime/util" "github.com/spf13/cobra" ) // fuzzyparseCmd represents the fuzzyparse command var fuzzyparseCmd = &cobra.Command{ Use: "fuzzyparse", - 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("fuzzyparse called") + Short: "Fuzzy parse the given text into a RFC3339 date", + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) > 0 { + if start, err := util.ParseFuzzyTime(args[0]); err == nil { + fmt.Println(start.Format(time.RFC3339)) + } else { + return err + } + } + return nil }, } func init() { rootCmd.AddCommand(fuzzyparseCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // fuzzyparseCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // fuzzyparseCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/i3status.go b/cmd/i3status.go index 55364cf..50bd73d 100644 --- a/cmd/i3status.go +++ b/cmd/i3status.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd diff --git a/cmd/list.go b/cmd/list.go index ee4f9a1..180a551 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd diff --git a/cmd/mod.go b/cmd/mod.go index ee61e48..800d09b 100644 --- a/cmd/mod.go +++ b/cmd/mod.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("mod called") - }, + RunE: opMod, } func init() { rootCmd.AddCommand(modCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // modCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // modCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opMod(cmd *cobra.Command, args []string) error { + fmt.Println("mod called") + return nil } diff --git a/cmd/rm.go b/cmd/rm.go index 078affc..9789204 100644 --- a/cmd/rm.go +++ b/cmd/rm.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("rm called") - }, + RunE: opRemove, } func init() { rootCmd.AddCommand(rmCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // rmCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // rmCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opRemove(cmd *cobra.Command, args []string) error { + fmt.Println("remove called") + return nil } diff --git a/cmd/root.go b/cmd/root.go index 133e963..cf91957 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd diff --git a/cmd/start.go b/cmd/start.go index 01196fb..6d1c564 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("start called") - }, + RunE: opStart, } func init() { rootCmd.AddCommand(startCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // startCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // startCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opStart(cmd *cobra.Command, args []string) error { + fmt.Println("start called") + return nil } diff --git a/cmd/status.go b/cmd/status.go index 3c0a0f6..e4c7895 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd diff --git a/cmd/stop.go b/cmd/stop.go index ade4bee..535c442 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("stop called") - }, + RunE: opStop, } func init() { rootCmd.AddCommand(stopCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // stopCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // stopCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opStop(cmd *cobra.Command, args []string) error { + fmt.Println("stop called") + return nil } diff --git a/cmd/switch.go b/cmd/switch.go index 9f3200a..a442817 100644 --- a/cmd/switch.go +++ b/cmd/switch.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("switch called") - }, + RunE: opSwitch, } func init() { rootCmd.AddCommand(switchCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // switchCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // switchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opSwitch(cmd *cobra.Command, args []string) error { + fmt.Println("switch called") + return nil } diff --git a/cmd/time.go b/cmd/time.go index 1ab8b91..e5c0342 100644 --- a/cmd/time.go +++ b/cmd/time.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd diff --git a/cmd/toggle.go b/cmd/toggle.go index bfcf7d2..1d2861a 100644 --- a/cmd/toggle.go +++ b/cmd/toggle.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Brian Buller */ package cmd @@ -20,21 +20,14 @@ 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("toggle called") - }, + RunE: opToggle, } func init() { rootCmd.AddCommand(toggleCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // toggleCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // toggleCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opToggle(cmd *cobra.Command, args []string) error { + fmt.Println("toggle called") + return nil } diff --git a/cmd/ui.go b/cmd/ui.go index 675b7ba..4d268c9 100644 --- a/cmd/ui.go +++ b/cmd/ui.go @@ -1,6 +1,5 @@ /* -Copyright © 2022 NAME HERE - +Copyright © 2022 Brian Buller */ package cmd @@ -13,28 +12,15 @@ import ( // uiCmd represents the ui command var uiCmd = &cobra.Command{ Use: "ui", - 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("ui called") - }, + Short: "Start gime in TUI mode", + RunE: opUi, } func init() { rootCmd.AddCommand(uiCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // uiCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // uiCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func opUi(cmd *cobra.Command, args []string) error { + fmt.Println("ui called") + return nil }