Output errors to STDERR, add description for the usage page, etc

This commit is contained in:
webb 2020-09-04 10:55:35 -04:00
parent b771c1307c
commit 023af72e46
No known key found for this signature in database
GPG Key ID: 8B6F0D2784D22DB2
2 changed files with 8 additions and 6 deletions

11
main.go
View File

@ -3,7 +3,6 @@ package main
import ( import (
"gitea.com/webb/teal" "gitea.com/webb/teal"
"github.com/urfave/cli" "github.com/urfave/cli"
"log"
"os" "os"
) )
@ -13,14 +12,17 @@ var itCl = teal.Client{
func main() { func main() {
cli := &cli.App{ cli := &cli.App{
Name: "interrupt",
Usage: "a simple CLI for pxl.blue",
Description: "This is a simple CLI for pxl.blue. You can upload images, get account information and more.",
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "upload", Name: "upload",
Aliases: []string{"u"}, Aliases: []string{"u"},
Usage: "upload a file", Usage: "upload a file",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
uploadHandler(c.Args().First()) err := uploadHandler(c.Args().First())
return nil return err
}, },
}, },
{ {
@ -43,6 +45,7 @@ func main() {
err := cli.Run(os.Args) err := cli.Run(os.Args)
if err != nil { if err != nil {
log.Fatal(err) os.Stderr.WriteString("interrupt: " + err.Error() + "\n")
os.Exit(1)
} }
} }

View File

@ -9,8 +9,7 @@ import (
func uploadHandler(a string) error { func uploadHandler(a string) error {
uploadKey, err := getUploadKey() uploadKey, err := getUploadKey()
if err != nil { if err != nil {
fmt.Println(err) return err
os.Exit(1)
} }
var reader io.Reader var reader io.Reader