work/cmd.go

75 lines
1.7 KiB
Go

package main
import (
"log"
"os"
"github.com/spf13/cobra"
)
func (a *App) setupCommands() *cobra.Command {
rootCmd := &cobra.Command{
Use: "work",
Short: "Fast work interactions",
Long: `A CLI tool to perform basic work cli tasks.`,
}
rootCmd.AddCommand(a.startCommand())
rootCmd.AddCommand(a.stopCommand())
rootCmd.AddCommand(a.showCommand())
return rootCmd
}
func (a *App) startCommand() *cobra.Command {
return &cobra.Command{
Use: "start",
Short: "start work",
Long: "command to start the work day",
Run: func(cmd *cobra.Command, args []string) {
a.connect()
},
}
}
func (a *App) stopCommand() *cobra.Command {
return &cobra.Command{
Use: "stop",
Short: "stop work",
Long: "command to stop the work day",
Run: func(cmd *cobra.Command, args []string) {
tw := NewTimeWarrior()
tw.StopWork()
if err := a.killForwardings(); err != nil {
log.Printf("error stoping port forwarding: %v", err)
}
os.Exit(0)
},
}
}
func (a *App) showCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Short: "show timetracking",
Long: "show different timetracking",
Run: func(cmd *cobra.Command, args []string) {
tw := NewTimeWarrior()
if a.flags.ShowExport {
tw.ExportSummary()
}
if a.flags.ShowWeek {
tw.ShowSummary(":week")
}
if a.flags.ShowMonth {
tw.ShowSummary(":month")
}
os.Exit(0)
},
}
cmd.Flags().BoolVarP(&a.flags.ShowWeek, "week", "w", false, "show timewarrior week summary")
cmd.Flags().BoolVarP(&a.flags.ShowMonth, "month", "m", false, "show timewarrior month summary")
cmd.Flags().BoolVarP(&a.flags.ShowExport, "export", "e", false, "export timewarrior timetable")
return cmd
}