-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (41 loc) · 943 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/michaellindman/discoupload/upload"
"github.com/pkg/errors"
)
func main() {
if err := run(); err != nil {
log.Fatalf("%s\n", err)
}
}
func run() error {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return errors.Wrap(err, "directory")
}
cfg, err := NewConfig(dir + "/config.yml")
if err != nil {
return errors.Wrap(err, "config")
}
flag.Usage = func() {
fmt.Printf("Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
file := flag.String("file", "", "path for file to be uploaded")
flag.Parse()
if *file != "" {
upload, err := upload.Upload(cfg.API.Key, cfg.API.Username, cfg.API.URL, *file)
if err != nil {
return errors.Wrap(err, "upload")
}
fmt.Printf("Uploaded %v (%v): %v\n", upload["original_filename"], upload["human_filesize"], upload["url"])
return nil
}
flag.PrintDefaults()
return nil
}