This repository has been archived on 2019-06-27. You can view files and clone it, but cannot push or open issues/pull-requests.
am/cmd/am/am.go

59 lines
815 B
Go

package main
import (
"fmt"
"log"
"os"
"strings"
"git.crumpington.com/public/am/amclient"
)
func main() {
usage := func() {
fmt.Fprintf(
os.Stderr,
"\n\n%s <report URL> <action> [text]\n\n"+
"Action is one of `ping`, `log`, or `alert`.\n"+
"The `log` and `alert` actions require `text`.\n\n",
os.Args[0])
os.Exit(1)
}
if len(os.Args) < 3 {
usage()
}
reportURL := os.Args[1]
cl := amclient.New(reportURL)
action := os.Args[2]
var err error
switch action {
case "ping":
err = cl.Ping()
case "log":
if len(os.Args) < 4 {
usage()
}
err = cl.Log(strings.Join(os.Args[4:], " "))
case "alert":
if len(os.Args) < 4 {
usage()
}
err = cl.Alert(strings.Join(os.Args[4:], " "))
default:
usage()
}
if err != nil {
log.Fatalf("Error: %v", err)
}
}