-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.go
114 lines (98 loc) · 2.89 KB
/
commands.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package commands
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/danlamanna/rivet/config"
"github.com/danlamanna/rivet/girder"
"github.com/danlamanna/rivet/transfer"
"github.com/danlamanna/rivet/version"
log "github.com/sirupsen/logrus"
)
func Configure(ctx *girder.Context) {
reader := bufio.NewReader(os.Stdin)
var promptedURL string
for {
fmt.Print("girder url (e.g. data.kitware.com): ")
promptedURL, _ = reader.ReadString('\n')
promptedURL = strings.TrimSpace(promptedURL)
if promptedURL != "" {
break
}
}
validURL, err := girder.GetValidURL(promptedURL)
if err != nil {
ctx.Logger.Fatal(err)
}
ctx.URL = validURL
if err = ctx.CheckMinimumVersion(); err != nil {
log.Fatal(err)
}
var promptedAuth string
for {
fmt.Print("auth credentials (e.g. username:password, token, api-key): ")
promptedAuth, _ = reader.ReadString('\n')
promptedAuth = strings.TrimSpace(promptedAuth)
if promptedAuth != "" {
break
}
}
ctx.Auth = promptedAuth
if err = ctx.ValidateAuth(); err != nil {
log.Fatal(err)
}
config.WriteDefaultProfile(promptedAuth, validURL)
}
func Sync(ctx *girder.Context, source *string, dest *string) {
*source = strings.TrimSuffix(*source, "/")
*dest = strings.TrimSuffix(*dest, "/")
sourceIsGirder := strings.HasPrefix(*source, "girder://")
destIsGirder := strings.HasPrefix(*dest, "girder://")
if sourceIsGirder && destIsGirder {
log.Fatal("cannot sync between two girder instances")
} else if !sourceIsGirder && !destIsGirder {
log.Fatal("cannot sync between two local directories")
}
if destIsGirder {
if stat, err := os.Stat(*source); err != nil {
if os.IsNotExist(err) {
log.Fatalf("source directory %s does not exist.\n", *source)
} else {
log.Fatalf("failed to access source directory %s, err: %s.\n", *source, err)
}
} else if !stat.IsDir() {
log.Fatalf("source %s is not a directory.\n", *source)
}
}
ctx.ResourceMap = make(girder.ResourceMap)
ctx.Destination = strings.TrimPrefix(*dest, "girder://")
if err := ctx.CheckMinimumVersion(); err != nil {
log.Fatal(err)
}
if err := ctx.ValidateAuth(); err != nil {
log.Warn(err)
}
if destIsGirder {
transfer.Upload(ctx, *source, girder.GirderID(*dest))
} else if sourceIsGirder {
transfer.Download(ctx, girder.GirderID(strings.TrimPrefix(*source, "girder://")), *dest)
}
}
func Version() {
fmt.Printf("rivet v%s\n", version.Version)
fmt.Printf("build: %s\n", version.GitCommit)
fmt.Printf("built: %s\n", version.BuildDate)
fmt.Printf("go version: %s\n", version.GoVersion)
fmt.Printf("os/arch: %s\n", version.OsArch)
}
func APICreateFolder(ctx *girder.Context, dest string, path string) {
if err := ctx.ValidateAuth(); err != nil {
log.Fatal(err)
}
ctx.ResourceMap = make(girder.ResourceMap)
ctx.ResourceMap[path] = new(girder.Resource)
ctx.Destination = dest
id, _ := girder.GetOrCreateFolderRecursive(ctx, path)
fmt.Println(id)
}