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

Commit f795261

Browse files
author
Marcin S
authored
Merge pull request #16 from NebulousLabs/fix-commands
Fix commands not working
2 parents e5a3adb + dfb2a16 commit f795261

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

cmd/skynet/skynetcmd.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ func skynetcmd() {
9797
func skynetaddskykeycmd(skykey string) {
9898
// Get the addskykey options.
9999
opts := skynet.DefaultAddSkykeyOptions
100-
client, commonOpts := initClientAndOptions()
101-
opts.Options = commonOpts
100+
client := initClientAndOptions(&opts.Options)
102101

103102
err := client.AddSkykey(skykey, opts)
104103
if err != nil {
@@ -112,8 +111,7 @@ func skynetaddskykeycmd(skykey string) {
112111
func skynetcreateskykeycmd(name, skykeyType string) {
113112
// Get the createskykey options.
114113
opts := skynet.DefaultCreateSkykeyOptions
115-
client, commonOpts := initClientAndOptions()
116-
opts.Options = commonOpts
114+
client := initClientAndOptions(&opts.Options)
117115

118116
skykey, err := client.CreateSkykey(name, skykeyType, opts)
119117
if err != nil {
@@ -126,8 +124,7 @@ func skynetcreateskykeycmd(name, skykeyType string) {
126124
func skynetgetskykeyidcmd(id string) {
127125
// Get the getskykeyid options.
128126
opts := skynet.DefaultGetSkykeyOptions
129-
client, commonOpts := initClientAndOptions()
130-
opts.Options = commonOpts
127+
client := initClientAndOptions(&opts.Options)
131128

132129
skykey, err := client.GetSkykeyByID(id, opts)
133130
if err != nil {
@@ -140,8 +137,7 @@ func skynetgetskykeyidcmd(id string) {
140137
func skynetgetskykeynamecmd(name string) {
141138
// Get the getskykeyname options.
142139
opts := skynet.DefaultGetSkykeyOptions
143-
client, commonOpts := initClientAndOptions()
144-
opts.Options = commonOpts
140+
client := initClientAndOptions(&opts.Options)
145141

146142
skykey, err := client.GetSkykeyByName(name, opts)
147143
if err != nil {
@@ -155,8 +151,7 @@ func skynetgetskykeynamecmd(name string) {
155151
func skynetgetskykeyscmd() {
156152
// Get the getskykeys options.
157153
opts := skynet.DefaultGetSkykeysOptions
158-
client, commonOpts := initClientAndOptions()
159-
opts.Options = commonOpts
154+
client := initClientAndOptions(&opts.Options)
160155

161156
skykeys, err := client.GetSkykeys(opts)
162157
if err != nil {
@@ -179,8 +174,7 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
179174

180175
// Get the download options.
181176
opts := skynet.DefaultDownloadOptions
182-
client, commonOpts := initClientAndOptions()
183-
opts.Options = commonOpts
177+
client := initClientAndOptions(&opts.Options)
184178
if downloadSkykeyName != "" {
185179
opts.SkykeyName = downloadSkykeyName
186180
}
@@ -202,8 +196,7 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
202196
func skynetuploadcmd(sourcePath string) {
203197
// Get the upload options.
204198
opts := skynet.DefaultUploadOptions
205-
client, commonOpts := initClientAndOptions()
206-
opts.Options = commonOpts
199+
client := initClientAndOptions(&opts.Options)
207200
if portalFileFieldName != "" {
208201
opts.PortalFileFieldName = portalFileFieldName
209202
}
@@ -239,13 +232,15 @@ func upload(sourcePath string, client skynet.SkynetClient, opts skynet.UploadOpt
239232
if err != nil {
240233
return "", "path", errors.AddContext(err, "Unable to open source path")
241234
}
242-
defer func() {
243-
err = errors.Extend(err, errors.AddContext(file.Close(), "Unable to close file"))
244-
}()
245235
fi, err := file.Stat()
246236
if err != nil {
237+
err = errors.Extend(err, file.Close())
247238
return "", "path", errors.AddContext(err, "Unable to fetch source fileinfo")
248239
}
240+
err = file.Close()
241+
if err != nil {
242+
return "", "path", errors.AddContext(err, "Unable to close file")
243+
}
249244

250245
// Upload File
251246
if !fi.IsDir() {
@@ -267,8 +262,7 @@ func upload(sourcePath string, client skynet.SkynetClient, opts skynet.UploadOpt
267262
// initClientAndOptions initializes a client and common options from the
268263
// persistent root flags that are common to all commands. Any available options
269264
// 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{}
265+
func initClientAndOptions(opts *skynet.Options) skynet.SkynetClient {
272266
if endpointPath != "" {
273267
opts.EndpointPath = endpointPath
274268
}
@@ -281,5 +275,5 @@ func initClientAndOptions() (skynet.SkynetClient, skynet.Options) {
281275
// Create a client with specified portal (or "" if not specified) default
282276
// options. Custom options will be passed into the API call itself.
283277
client := skynet.NewCustom(skynetPortal, skynet.Options{})
284-
return client, opts
278+
return client
285279
}

0 commit comments

Comments
 (0)