-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (53 loc) · 1.66 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"flag"
"fmt"
"os"
"github.com/kurin/blazer/b2"
)
// B2Client - a temporary global pointer to an authenticated b2.Client
var B2Client *b2.Client
func run(isPipeMode bool, allowDirectories bool, bucketName string, args []string) error {
if isPipeMode {
if allowDirectories {
return errors.New("directory mode and pipe mode are mutually exclusive")
}
return handlePipeMode(bucketName, args)
}
if len(args) > 0 {
fmt.Println("About to upload the following file[/s]:", args)
confirmed, err := confirmAction()
if nil != err {
return err
}
if confirmed {
return handleFiles(bucketName, args, allowDirectories)
}
}
return nil
}
func main() {
var isPipeMode bool
var allowDirectories bool
var bucketName string
flag.BoolVar(&isPipeMode, "pipe", false,
"Read and upload data from STDIN until EOF is reached. Does NOT ask for confirmation."+
"If your account has more than one bucket available, '-bucket' flag is required")
flag.BoolVar(&allowDirectories, "dir", false,
"Upload directories (recursively). When this option is not specified, directories are ignored")
flag.StringVar(&bucketName, "bucket", "", "name of destination bucket")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "\nUp - A simple utility for uploading stuff to BackBlaze's B2\n\n")
fmt.Fprintf(os.Stderr, "Usage: up [-bucket BUCKET_NAME] [-pipe TARGET_NAME] [-dir] [file1 .. fileN]\n\n")
flag.PrintDefaults()
}
flag.Parse()
args := flag.Args()
fmt.Printf("\nUp⤴️\n\n")
if err := run(isPipeMode, allowDirectories, bucketName, args); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
fmt.Println("\ndone")
}