diff --git a/main.go b/main.go index e2273dc..6613fba 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "time" "github.com/charmbracelet/huh" + "github.com/spf13/cobra" "github.com/spf13/viper" "golang.org/x/crypto/ssh" ) @@ -22,7 +23,7 @@ type Config struct { JumpUser string `mapstructure:"JUMP_USER"` JumpHost string `mapstructure:"JUMP_HOST"` WorkstationHost string `mapstructure:"WORKSTATION_HOST"` - WorkstationUser string `mapstructure:"WWORKSTATION_USER"` + WorkstationUser string `mapstructure:"WORKSTATION_USER"` WorkstationMac string `mapstructure:"WORKSTATION_MAC"` RDPUser string `mapstructure:"RDP_USER"` RDPPassword string `mapstructure:"RDP_PASSWORD"` @@ -30,9 +31,24 @@ type Config struct { SSHPort int `mapstructure:"SSH_PORT"` } -var cfg Config +type Flags struct { + ShowWeek bool + ShowMonth bool + ShowExport bool +} + +var ( + cfg Config + flags Flags +) func init() { + showCmd.Flags().BoolVarP(&flags.ShowWeek, "week", "w", false, "show timewarrior week summary") + showCmd.Flags().BoolVarP(&flags.ShowMonth, "month", "m", false, "show timewarrior month summary") + showCmd.Flags().BoolVarP(&flags.ShowExport, "export", "e", false, "export timewarrior timetable") + rootCmd.AddCommand(startCmd) + rootCmd.AddCommand(stopCmd) + rootCmd.AddCommand(showCmd) log.Println("Loading Config File") configPath, err := os.UserConfigDir() if err != nil { @@ -50,8 +66,8 @@ func init() { if err != nil { log.Printf("error loading config file: %v", err) } - allSettings := viper.AllSettings() - log.Printf("All loaded settings: %+v", allSettings) + // allSettings := viper.AllSettings() + // log.Printf("All loaded settings: %+v", allSettings) err = viper.UnmarshalKey("default", &cfg) if err != nil { @@ -248,6 +264,56 @@ func makeChoice() { } } -func main() { - makeChoice() +var rootCmd = &cobra.Command{ + Use: "work", + Short: "Fast work interactions", + Long: `A CLI tool to perform basic work cli tasks.`, +} + +var startCmd = &cobra.Command{ + Use: "start", + Short: "start work", + Long: "command to start the work day", + Run: func(cmd *cobra.Command, args []string) { + connect() + }, +} + +var stopCmd = &cobra.Command{ + Use: "stop", + Short: "stop work", + Long: "command to stop the work day", + Run: func(cmd *cobra.Command, args []string) { + runCommand("timew", "stop", "work") + os.Exit(0) + }, +} + +var showCmd = &cobra.Command{ + Use: "show", + Short: "show timetracking", + Long: "show different timetracking", + Run: func(cmd *cobra.Command, args []string) { + if flags.ShowExport { + fmt.Println("Exporting timetable") + } + if flags.ShowWeek { + runCommand("timew", "summary", ":week", "work") + } + if flags.ShowMonth { + runCommand("timew", "summary", ":month", "work") + } + os.Exit(0) + }, +} + +func main() { + if len(os.Args) > 1 { + if err := rootCmd.Execute(); err != nil { + log.Fatalf("error executing command: %v", err) + } + // return + } else { + makeChoice() + } }