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

Commit

Permalink
Merge pull request #16 from NebulousLabs/fix-commands
Browse files Browse the repository at this point in the history
Fix commands not working
  • Loading branch information
Marcin S authored Oct 22, 2020
2 parents e5a3adb + dfb2a16 commit f795261
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions cmd/skynet/skynetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func skynetcmd() {
func skynetaddskykeycmd(skykey string) {
// Get the addskykey options.
opts := skynet.DefaultAddSkykeyOptions
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
client := initClientAndOptions(&opts.Options)

err := client.AddSkykey(skykey, opts)
if err != nil {
Expand All @@ -112,8 +111,7 @@ func skynetaddskykeycmd(skykey string) {
func skynetcreateskykeycmd(name, skykeyType string) {
// Get the createskykey options.
opts := skynet.DefaultCreateSkykeyOptions
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
client := initClientAndOptions(&opts.Options)

skykey, err := client.CreateSkykey(name, skykeyType, opts)
if err != nil {
Expand All @@ -126,8 +124,7 @@ func skynetcreateskykeycmd(name, skykeyType string) {
func skynetgetskykeyidcmd(id string) {
// Get the getskykeyid options.
opts := skynet.DefaultGetSkykeyOptions
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
client := initClientAndOptions(&opts.Options)

skykey, err := client.GetSkykeyByID(id, opts)
if err != nil {
Expand All @@ -140,8 +137,7 @@ func skynetgetskykeyidcmd(id string) {
func skynetgetskykeynamecmd(name string) {
// Get the getskykeyname options.
opts := skynet.DefaultGetSkykeyOptions
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
client := initClientAndOptions(&opts.Options)

skykey, err := client.GetSkykeyByName(name, opts)
if err != nil {
Expand All @@ -155,8 +151,7 @@ func skynetgetskykeynamecmd(name string) {
func skynetgetskykeyscmd() {
// Get the getskykeys options.
opts := skynet.DefaultGetSkykeysOptions
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
client := initClientAndOptions(&opts.Options)

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

// Get the download options.
opts := skynet.DefaultDownloadOptions
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
client := initClientAndOptions(&opts.Options)
if downloadSkykeyName != "" {
opts.SkykeyName = downloadSkykeyName
}
Expand All @@ -202,8 +196,7 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
func skynetuploadcmd(sourcePath string) {
// Get the upload options.
opts := skynet.DefaultUploadOptions
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
client := initClientAndOptions(&opts.Options)
if portalFileFieldName != "" {
opts.PortalFileFieldName = portalFileFieldName
}
Expand Down Expand Up @@ -239,13 +232,15 @@ func upload(sourcePath string, client skynet.SkynetClient, opts skynet.UploadOpt
if err != nil {
return "", "path", errors.AddContext(err, "Unable to open source path")
}
defer func() {
err = errors.Extend(err, errors.AddContext(file.Close(), "Unable to close file"))
}()
fi, err := file.Stat()
if err != nil {
err = errors.Extend(err, file.Close())
return "", "path", errors.AddContext(err, "Unable to fetch source fileinfo")
}
err = file.Close()
if err != nil {
return "", "path", errors.AddContext(err, "Unable to close file")
}

// Upload File
if !fi.IsDir() {
Expand All @@ -267,8 +262,7 @@ func upload(sourcePath string, client skynet.SkynetClient, opts skynet.UploadOpt
// initClientAndOptions initializes a client and common options from the
// persistent root flags that are common to all commands. Any available options
// in `opts` will be used if the option is not overridden with a root flag.
func initClientAndOptions() (skynet.SkynetClient, skynet.Options) {
opts := skynet.Options{}
func initClientAndOptions(opts *skynet.Options) skynet.SkynetClient {
if endpointPath != "" {
opts.EndpointPath = endpointPath
}
Expand All @@ -281,5 +275,5 @@ func initClientAndOptions() (skynet.SkynetClient, skynet.Options) {
// Create a client with specified portal (or "" if not specified) default
// options. Custom options will be passed into the API call itself.
client := skynet.NewCustom(skynetPortal, skynet.Options{})
return client, opts
return client
}

0 comments on commit f795261

Please sign in to comment.