func cmdDetail(c *statuscake.Client, args ...string) error { if len(args) != 1 { return fmt.Errorf("command `detail` requires a single argument `TestID`") } id, err := strconv.Atoi(args[0]) if err != nil { return err } tt := c.Tests() t, err := tt.Detail(id) if err != nil { return err } var paused string if t.Paused { paused = "yes" } else { paused = "no" } fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) fmt.Printf(" WebsiteURL: %s\n", t.WebsiteURL) fmt.Printf(" PingURL: %s\n", t.PingURL) fmt.Printf(" TestType: %s\n", t.TestType) fmt.Printf(" Paused: %s\n", paused) fmt.Printf(" ContactID: %d\n", t.ContactID) fmt.Printf(" Uptime: %f\n", t.Uptime) return nil }
func cmdList(c *statuscake.Client, args ...string) error { tt := c.Tests() tests, err := tt.All() if err != nil { return err } for _, t := range tests { var paused string if t.Paused { paused = "yes" } else { paused = "no" } fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) fmt.Printf(" TestType: %s\n", t.TestType) fmt.Printf(" Paused: %s\n", paused) fmt.Printf(" ContactID: %d\n", t.ContactID) fmt.Printf(" Uptime: %f\n", t.Uptime) } return nil }
func cmdUpdate(c *statuscake.Client, args ...string) error { if len(args) != 1 { return fmt.Errorf("command `update` requires a single argument `TestID`") } id, err := strconv.Atoi(args[0]) if err != nil { return err } tt := c.Tests() t, err := tt.Detail(id) if err != nil { return err } t.TestID = id t.WebsiteName = askString(fmt.Sprintf("WebsiteName [%s]", t.WebsiteName)) t.WebsiteURL = askString(fmt.Sprintf("WebsiteURL [%s]", t.WebsiteURL)) t.TestType = askString(fmt.Sprintf("TestType [%s]", t.TestType)) t.CheckRate = askInt(fmt.Sprintf("CheckRate [%d]", t.CheckRate)) t2, err := c.Tests().Update(t) if err != nil { return err } fmt.Printf("UPDATED: \n%+v\n", t2) return nil }
func cmdDelete(c *statuscake.Client, args ...string) error { if len(args) != 1 { return fmt.Errorf("command `delete` requires a single argument `TestID`") } id, err := strconv.Atoi(args[0]) if err != nil { return err } return c.Tests().Delete(id) }
func cmdCreate(c *statuscake.Client, args ...string) error { t := &statuscake.Test{ WebsiteName: askString("WebsiteName"), WebsiteURL: askString("WebsiteURL"), TestType: askString("TestType"), CheckRate: askInt("CheckRate"), } t2, err := c.Tests().Update(t) if err != nil { return err } fmt.Printf("CREATED: \n%+v\n", t2) return nil }