Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Commit 99ff022

Browse files
author
Marcin S
committed
Version update to v2.0.0
1 parent 62bdb59 commit 99ff022

File tree

5 files changed

+46
-48
lines changed

5 files changed

+46
-48
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ Version History
1010

1111
Latest:
1212

13+
## Sep 4, 2020:
14+
### v2.0.0
15+
**Key Updates**
16+
- Updated to use v2 of the API.
17+
- Added `version` command.
18+
1319
## Aug 13, 2020:
1420
### v1.1.0
1521
**Key Updates**
@@ -20,5 +26,4 @@ Latest:
2026
## Jun 16, 2020:
2127
### v1.0.0
2228
**Key Updates**
23-
- Created skynet cli
24-
29+
- Created skynet cli with upload and download.

cmd/skynet/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ built on top of Sia.`
2626
mainDocFile = "./doc/skynet.md"
2727

2828
// version is the current version of skynet-cli.
29-
version = "1.1.0"
29+
version = "2.0.0"
3030
)
3131

3232
// Exit codes.

cmd/skynet/skynetcmd.go

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/NebulousLabs/go-skynet"
7+
"github.com/NebulousLabs/go-skynet/v2"
88
"github.com/spf13/cobra"
99
"gitlab.com/NebulousLabs/errors"
1010
)
@@ -89,17 +89,18 @@ func skynetcmd() {
8989
fmt.Printf("%s\n\n", binDescription)
9090

9191
// Get Default Portal
92-
fmt.Printf("Default Skynet Portal: %v\n", skynet.DefaultPortalURL)
92+
fmt.Printf("Default Skynet Portal: %v\n", skynet.DefaultPortalURL())
9393
}
9494

9595
// skynetaddskykey stores the given base-64 encoded skykey with the skykey
9696
// manager.
9797
func skynetaddskykeycmd(skykey string) {
9898
// Get the addskykey options.
9999
opts := skynet.DefaultAddSkykeyOptions
100-
opts.Options = getCommonOptions(opts.Options)
100+
client, commonOpts := initClientAndOptions()
101+
opts.Options = commonOpts
101102

102-
err := skynet.AddSkykey(skykey, opts)
103+
err := client.AddSkykey(skykey, opts)
103104
if err != nil {
104105
err = errors.AddContext(err, fmt.Sprintf("AddSkykey Options: %+v\n", opts))
105106
die("Unable to add skykey:", err)
@@ -111,9 +112,10 @@ func skynetaddskykeycmd(skykey string) {
111112
func skynetcreateskykeycmd(name, skykeyType string) {
112113
// Get the createskykey options.
113114
opts := skynet.DefaultCreateSkykeyOptions
114-
opts.Options = getCommonOptions(opts.Options)
115+
client, commonOpts := initClientAndOptions()
116+
opts.Options = commonOpts
115117

116-
skykey, err := skynet.CreateSkykey(name, skykeyType, opts)
118+
skykey, err := client.CreateSkykey(name, skykeyType, opts)
117119
if err != nil {
118120
err = errors.AddContext(err, fmt.Sprintf("CreateSkykey Options: %+v\n", opts))
119121
die("Unable to create skykey:", err)
@@ -124,9 +126,10 @@ func skynetcreateskykeycmd(name, skykeyType string) {
124126
func skynetgetskykeyidcmd(id string) {
125127
// Get the getskykeyid options.
126128
opts := skynet.DefaultGetSkykeyOptions
127-
opts.Options = getCommonOptions(opts.Options)
129+
client, commonOpts := initClientAndOptions()
130+
opts.Options = commonOpts
128131

129-
skykey, err := skynet.GetSkykeyByID(id, opts)
132+
skykey, err := client.GetSkykeyByID(id, opts)
130133
if err != nil {
131134
err = errors.AddContext(err, fmt.Sprintf("GetSkykey Options: %+v\n", opts))
132135
die("Unable to get skykey by id:", err)
@@ -137,9 +140,10 @@ func skynetgetskykeyidcmd(id string) {
137140
func skynetgetskykeynamecmd(name string) {
138141
// Get the getskykeyname options.
139142
opts := skynet.DefaultGetSkykeyOptions
140-
opts.Options = getCommonOptions(opts.Options)
143+
client, commonOpts := initClientAndOptions()
144+
opts.Options = commonOpts
141145

142-
skykey, err := skynet.GetSkykeyByName(name, opts)
146+
skykey, err := client.GetSkykeyByName(name, opts)
143147
if err != nil {
144148
err = errors.AddContext(err, fmt.Sprintf("GetSkykey Options: %+v\n", opts))
145149
die("Unable to get skykey by name:", err)
@@ -151,9 +155,10 @@ func skynetgetskykeynamecmd(name string) {
151155
func skynetgetskykeyscmd() {
152156
// Get the getskykeys options.
153157
opts := skynet.DefaultGetSkykeysOptions
154-
opts.Options = getCommonOptions(opts.Options)
158+
client, commonOpts := initClientAndOptions()
159+
opts.Options = commonOpts
155160

156-
skykeys, err := skynet.GetSkykeys(opts)
161+
skykeys, err := client.GetSkykeys(opts)
157162
if err != nil {
158163
err = errors.AddContext(err, fmt.Sprintf("GetSkykeys Options: %+v\n", opts))
159164
die("Unable to get skykeys:", err)
@@ -174,7 +179,8 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
174179

175180
// Get the download options.
176181
opts := skynet.DefaultDownloadOptions
177-
opts.Options = getCommonOptions(opts.Options)
182+
client, commonOpts := initClientAndOptions()
183+
opts.Options = commonOpts
178184
if downloadSkykeyName != "" {
179185
opts.SkykeyName = downloadSkykeyName
180186
}
@@ -183,7 +189,7 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
183189
}
184190

185191
// Download Skylink
186-
err := skynet.DownloadFile(filename, skylink, opts)
192+
err := client.DownloadFile(filename, skylink, opts)
187193
if err != nil {
188194
err = errors.AddContext(err, fmt.Sprintf("Download Options: %+v\n", opts))
189195
die("Unable to download skylink:", err)
@@ -196,7 +202,8 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
196202
func skynetuploadcmd(sourcePath string) {
197203
// Get the upload options.
198204
opts := skynet.DefaultUploadOptions
199-
opts.Options = getCommonOptions(opts.Options)
205+
client, commonOpts := initClientAndOptions()
206+
opts.Options = commonOpts
200207
if portalFileFieldName != "" {
201208
opts.PortalFileFieldName = portalFileFieldName
202209
}
@@ -216,7 +223,7 @@ func skynetuploadcmd(sourcePath string) {
216223
opts.SkykeyID = uploadSkykeyID
217224
}
218225

219-
skylink, uploadType, err := upload(sourcePath, opts)
226+
skylink, uploadType, err := upload(sourcePath, client, opts)
220227
if err != nil {
221228
err = errors.AddContext(err, fmt.Sprintf("Upload Options: %+v\n", opts))
222229
die(fmt.Sprintf("Unable to upload %v: %v\n", uploadType, err))
@@ -226,7 +233,7 @@ func skynetuploadcmd(sourcePath string) {
226233
}
227234

228235
// upload uploads the given path.
229-
func upload(sourcePath string, opts skynet.UploadOptions) (skylink string, uploadType string, err error) {
236+
func upload(sourcePath string, client skynet.SkynetClient, opts skynet.UploadOptions) (skylink string, uploadType string, err error) {
230237
// Open the source file.
231238
file, err := os.Open(sourcePath)
232239
if err != nil {
@@ -242,27 +249,26 @@ func upload(sourcePath string, opts skynet.UploadOptions) (skylink string, uploa
242249

243250
// Upload File
244251
if !fi.IsDir() {
245-
skylink, err = skynet.UploadFile(sourcePath, opts)
252+
skylink, err = client.UploadFile(sourcePath, opts)
246253
if err != nil {
247254
return "", "file", errors.AddContext(err, "Unable to upload file")
248255
}
249256
return skylink, "file", nil
250257
}
251258

252259
// Upload directory
253-
skylink, err = skynet.UploadDirectory(sourcePath, opts)
260+
skylink, err = client.UploadDirectory(sourcePath, opts)
254261
if err != nil {
255262
return "", "directory", errors.AddContext(err, "Unable to upload directory")
256263
}
257264
return skylink, "directory", nil
258265
}
259266

260-
// getCommonOptions gets options from the persistent root flags that are common
261-
// to all commands.
262-
func getCommonOptions(opts skynet.Options) skynet.Options {
263-
if skynetPortal != "" {
264-
opts.PortalURL = skynetPortal
265-
}
267+
// initClientAndOptions initializes a client and common options from the
268+
// persistent root flags that are common to all commands. Any available options
269+
// in `opts` will be used if the option is not overridden with a root flag.
270+
func initClientAndOptions() (skynet.SkynetClient, skynet.Options) {
271+
opts := skynet.Options{}
266272
if endpointPath != "" {
267273
opts.EndpointPath = endpointPath
268274
}
@@ -272,5 +278,8 @@ func getCommonOptions(opts skynet.Options) skynet.Options {
272278
if customUserAgent != "" {
273279
opts.CustomUserAgent = customUserAgent
274280
}
275-
return opts
281+
// Create a client with specified portal (or "" if not specified) default
282+
// options. Custom options will be passed into the API call itself.
283+
client := skynet.NewCustom(skynetPortal, skynet.Options{})
284+
return client, opts
276285
}

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ module github.com/NebulousLabs/skynet-cli
33
go 1.13
44

55
require (
6-
github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66
6+
github.com/NebulousLabs/go-skynet/v2 v2.0.0
77
github.com/spf13/cobra v1.0.0
88
github.com/spf13/pflag v1.0.5 // indirect
99
gitlab.com/NebulousLabs/errors v0.0.0-20171229012116-7ead97ef90b8
10-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
1110
gopkg.in/yaml.v2 v2.3.0 // indirect
1211
)

go.sum

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3-
github.com/NebulousLabs/go-skynet v0.0.0-20200615123241-9b30d4ffd492 h1:KPJHmIBb5szkxU4acjpLVFQxPIU/vfjhghAYxEixuNU=
4-
github.com/NebulousLabs/go-skynet v0.0.0-20200615123241-9b30d4ffd492/go.mod h1:uOpyXOndZfQYn/hIdGgR0DJCK2I4uz+NNmXtxlaCUyg=
5-
github.com/NebulousLabs/go-skynet v0.0.0-20200721163935-c56e138c1a03 h1:E+UMrK7thvS73wxDhTgE35fxN0hSCT6KBI2vWao4zj8=
6-
github.com/NebulousLabs/go-skynet v0.0.0-20200721163935-c56e138c1a03/go.mod h1:6vr7Kb2aMpGrAuLmZ2LOtuqLusO1ISRglRXDv+vkmdI=
7-
github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66 h1:dboQMHW8YhTQcsjnBB/s4ZPXk/O1Jf8R6O9BaStll2o=
8-
github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66/go.mod h1:6vr7Kb2aMpGrAuLmZ2LOtuqLusO1ISRglRXDv+vkmdI=
3+
github.com/NebulousLabs/go-skynet/v2 v2.0.0 h1:hPgml8Qc5RalldibBZ9p66Oggoud45OIZZnut9pWNUo=
4+
github.com/NebulousLabs/go-skynet/v2 v2.0.0/go.mod h1:uhGD1M7Qe1nXsnqRD90B5CJVgjqSqwJUmDosgAn4CdQ=
95
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
106
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
117
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -120,42 +116,31 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
120116
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
121117
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
122118
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
123-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
124119
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
125120
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=
126121
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
127-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
128-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
129-
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
130122
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
131123
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
132124
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
133125
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
134-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
135126
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
136-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
137127
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
138128
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
139129
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
140130
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
141-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
142131
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
143132
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
144133
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
145134
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
146135
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
147136
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
148-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
149137
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
150138
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
151139
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
152140
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
153141
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
154142
golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ=
155143
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
156-
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY=
157-
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
158-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
159144
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
160145
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
161146
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=

0 commit comments

Comments
 (0)