feat: add cli commands for start, stop and show
This commit is contained in:
parent
35dd5d7885
commit
c052e6daf0
1 changed files with 72 additions and 6 deletions
78
main.go
78
main.go
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/huh"
|
"github.com/charmbracelet/huh"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
@ -22,7 +23,7 @@ type Config struct {
|
||||||
JumpUser string `mapstructure:"JUMP_USER"`
|
JumpUser string `mapstructure:"JUMP_USER"`
|
||||||
JumpHost string `mapstructure:"JUMP_HOST"`
|
JumpHost string `mapstructure:"JUMP_HOST"`
|
||||||
WorkstationHost string `mapstructure:"WORKSTATION_HOST"`
|
WorkstationHost string `mapstructure:"WORKSTATION_HOST"`
|
||||||
WorkstationUser string `mapstructure:"WWORKSTATION_USER"`
|
WorkstationUser string `mapstructure:"WORKSTATION_USER"`
|
||||||
WorkstationMac string `mapstructure:"WORKSTATION_MAC"`
|
WorkstationMac string `mapstructure:"WORKSTATION_MAC"`
|
||||||
RDPUser string `mapstructure:"RDP_USER"`
|
RDPUser string `mapstructure:"RDP_USER"`
|
||||||
RDPPassword string `mapstructure:"RDP_PASSWORD"`
|
RDPPassword string `mapstructure:"RDP_PASSWORD"`
|
||||||
|
|
@ -30,9 +31,24 @@ type Config struct {
|
||||||
SSHPort int `mapstructure:"SSH_PORT"`
|
SSHPort int `mapstructure:"SSH_PORT"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var cfg Config
|
type Flags struct {
|
||||||
|
ShowWeek bool
|
||||||
|
ShowMonth bool
|
||||||
|
ShowExport bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
cfg Config
|
||||||
|
flags Flags
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
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")
|
log.Println("Loading Config File")
|
||||||
configPath, err := os.UserConfigDir()
|
configPath, err := os.UserConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -50,8 +66,8 @@ func init() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error loading config file: %v", err)
|
log.Printf("error loading config file: %v", err)
|
||||||
}
|
}
|
||||||
allSettings := viper.AllSettings()
|
// allSettings := viper.AllSettings()
|
||||||
log.Printf("All loaded settings: %+v", allSettings)
|
// log.Printf("All loaded settings: %+v", allSettings)
|
||||||
|
|
||||||
err = viper.UnmarshalKey("default", &cfg)
|
err = viper.UnmarshalKey("default", &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -248,6 +264,56 @@ func makeChoice() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
var rootCmd = &cobra.Command{
|
||||||
makeChoice()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue