refactor: introduce TimeWarrior struct
This commit is contained in:
parent
aa3000cce6
commit
fec43ea77d
1 changed files with 49 additions and 9 deletions
58
main.go
58
main.go
|
|
@ -79,7 +79,9 @@ func loadConfig() (Config, error) {
|
|||
}
|
||||
|
||||
func (a *App) connect() {
|
||||
a.runCommand("timew", "start", "work")
|
||||
tw := NewTimeWarrior()
|
||||
tw.StartWork()
|
||||
// a.runCommand("timew", "start", "work")
|
||||
a.wakeWorkstation()
|
||||
sshClient, err := ssh.Dial("tcp", a.cfg.SSHHost+":"+fmt.Sprintf("%v", a.cfg.SSHPort), a.makeSSHClient())
|
||||
if err != nil {
|
||||
|
|
@ -205,6 +207,7 @@ func (a *App) startRDPConnection() {
|
|||
|
||||
func (a *App) makeChoice() {
|
||||
var choice string
|
||||
tw := NewTimeWarrior()
|
||||
form := huh.NewForm(
|
||||
huh.NewGroup(
|
||||
huh.NewSelect[string]().
|
||||
|
|
@ -235,17 +238,16 @@ func (a *App) makeChoice() {
|
|||
switch choice {
|
||||
case "Start":
|
||||
a.connect()
|
||||
// startSequence()
|
||||
case "stop Work":
|
||||
a.runCommand("timew", "stop", "work")
|
||||
tw.StopWork()
|
||||
case "start break":
|
||||
a.runCommand("timew", "track", "break")
|
||||
tw.StartBreak()
|
||||
case "stop break":
|
||||
a.runCommand("timew", "track", "work")
|
||||
tw.StopBreak()
|
||||
case "show week summary":
|
||||
a.runCommand("timew", "summary", ":week", "work")
|
||||
tw.ShowSummary(":week")
|
||||
case "show month summary":
|
||||
a.runCommand("timew", "summary", ":month", "work")
|
||||
tw.ShowSummary(":month")
|
||||
case "wake workstation":
|
||||
a.wakeWorkstation()
|
||||
case "connect to jump":
|
||||
|
|
@ -255,10 +257,49 @@ func (a *App) makeChoice() {
|
|||
case "start rdp connection":
|
||||
a.startRDPConnection()
|
||||
case "export":
|
||||
fmt.Println("Exporting Work times")
|
||||
tw.ExportSummary()
|
||||
}
|
||||
}
|
||||
|
||||
type TimeWarrior struct{}
|
||||
|
||||
func NewTimeWarrior() *TimeWarrior {
|
||||
return &TimeWarrior{}
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) runCommand(args ...string) error {
|
||||
cmd := exec.Command("timew", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) StartWork() error {
|
||||
return t.runCommand("start", "work")
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) StopWork() error {
|
||||
return t.runCommand("stop", "work")
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) StartBreak() error {
|
||||
return t.runCommand("track", "break")
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) StopBreak() error {
|
||||
return t.runCommand("track", "work")
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) ShowSummary(period string) error {
|
||||
return t.runCommand("summary", period, "work")
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) ExportSummary() error {
|
||||
fmt.Println("Export Timetable")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) setupCommands() *cobra.Command {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "work",
|
||||
|
|
@ -330,7 +371,6 @@ func main() {
|
|||
if err := app.setupCommands().Execute(); err != nil {
|
||||
log.Fatalf("error executing command: %v", err)
|
||||
}
|
||||
// return
|
||||
} else {
|
||||
app.makeChoice()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue