I believe that all functionality is implemented
This commit is contained in:
42
cmd/rm.go
42
cmd/rm.go
@@ -6,21 +6,18 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"git.bullercodeworks.com/brian/gime/cli"
|
||||
"git.bullercodeworks.com/brian/gime/util"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// rmCmd represents the rm command
|
||||
var rmCmd = &cobra.Command{
|
||||
Use: "rm",
|
||||
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.`,
|
||||
RunE: opRemove,
|
||||
Short: "Remove a timer",
|
||||
RunE: opRemove,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -28,6 +25,33 @@ func init() {
|
||||
}
|
||||
|
||||
func opRemove(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("remove called")
|
||||
var err error
|
||||
p := cli.Program{}
|
||||
err = p.Initialize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = p.LoadTimerList(); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("No timer id given")
|
||||
}
|
||||
id, err := strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid timer id given %s: %w", args[0], err)
|
||||
}
|
||||
t, err := p.TimerList.GetTimer(id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting timer with id %s: %w", args[0], err)
|
||||
}
|
||||
if err = p.TimerList.RemoveTimerById(id); err != nil {
|
||||
return fmt.Errorf("Error Removing Timer: %w", err)
|
||||
}
|
||||
fmt.Println("Timer removed")
|
||||
fmt.Println(util.TimerToString(t))
|
||||
if err := p.WriteTimerList(); err != nil {
|
||||
return fmt.Errorf("Error writing timer list: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user