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

Commit

Permalink
Version update to v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin S committed Sep 4, 2020
1 parent 62bdb59 commit 99ff022
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 48 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Version History

Latest:

## Sep 4, 2020:
### v2.0.0
**Key Updates**
- Updated to use v2 of the API.
- Added `version` command.

## Aug 13, 2020:
### v1.1.0
**Key Updates**
Expand All @@ -20,5 +26,4 @@ Latest:
## Jun 16, 2020:
### v1.0.0
**Key Updates**
- Created skynet cli

- Created skynet cli with upload and download.
2 changes: 1 addition & 1 deletion cmd/skynet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ built on top of Sia.`
mainDocFile = "./doc/skynet.md"

// version is the current version of skynet-cli.
version = "1.1.0"
version = "2.0.0"
)

// Exit codes.
Expand Down
61 changes: 35 additions & 26 deletions cmd/skynet/skynetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/NebulousLabs/go-skynet"
"github.com/NebulousLabs/go-skynet/v2"
"github.com/spf13/cobra"
"gitlab.com/NebulousLabs/errors"
)
Expand Down Expand Up @@ -89,17 +89,18 @@ func skynetcmd() {
fmt.Printf("%s\n\n", binDescription)

// Get Default Portal
fmt.Printf("Default Skynet Portal: %v\n", skynet.DefaultPortalURL)
fmt.Printf("Default Skynet Portal: %v\n", skynet.DefaultPortalURL())
}

// skynetaddskykey stores the given base-64 encoded skykey with the skykey
// manager.
func skynetaddskykeycmd(skykey string) {
// Get the addskykey options.
opts := skynet.DefaultAddSkykeyOptions
opts.Options = getCommonOptions(opts.Options)
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts

err := skynet.AddSkykey(skykey, opts)
err := client.AddSkykey(skykey, opts)
if err != nil {
err = errors.AddContext(err, fmt.Sprintf("AddSkykey Options: %+v\n", opts))
die("Unable to add skykey:", err)
Expand All @@ -111,9 +112,10 @@ func skynetaddskykeycmd(skykey string) {
func skynetcreateskykeycmd(name, skykeyType string) {
// Get the createskykey options.
opts := skynet.DefaultCreateSkykeyOptions
opts.Options = getCommonOptions(opts.Options)
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts

skykey, err := skynet.CreateSkykey(name, skykeyType, opts)
skykey, err := client.CreateSkykey(name, skykeyType, opts)
if err != nil {
err = errors.AddContext(err, fmt.Sprintf("CreateSkykey Options: %+v\n", opts))
die("Unable to create skykey:", err)
Expand All @@ -124,9 +126,10 @@ func skynetcreateskykeycmd(name, skykeyType string) {
func skynetgetskykeyidcmd(id string) {
// Get the getskykeyid options.
opts := skynet.DefaultGetSkykeyOptions
opts.Options = getCommonOptions(opts.Options)
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts

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

skykey, err := skynet.GetSkykeyByName(name, opts)
skykey, err := client.GetSkykeyByName(name, opts)
if err != nil {
err = errors.AddContext(err, fmt.Sprintf("GetSkykey Options: %+v\n", opts))
die("Unable to get skykey by name:", err)
Expand All @@ -151,9 +155,10 @@ func skynetgetskykeynamecmd(name string) {
func skynetgetskykeyscmd() {
// Get the getskykeys options.
opts := skynet.DefaultGetSkykeysOptions
opts.Options = getCommonOptions(opts.Options)
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts

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

// Get the download options.
opts := skynet.DefaultDownloadOptions
opts.Options = getCommonOptions(opts.Options)
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
if downloadSkykeyName != "" {
opts.SkykeyName = downloadSkykeyName
}
Expand All @@ -183,7 +189,7 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
}

// Download Skylink
err := skynet.DownloadFile(filename, skylink, opts)
err := client.DownloadFile(filename, skylink, opts)
if err != nil {
err = errors.AddContext(err, fmt.Sprintf("Download Options: %+v\n", opts))
die("Unable to download skylink:", err)
Expand All @@ -196,7 +202,8 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) {
func skynetuploadcmd(sourcePath string) {
// Get the upload options.
opts := skynet.DefaultUploadOptions
opts.Options = getCommonOptions(opts.Options)
client, commonOpts := initClientAndOptions()
opts.Options = commonOpts
if portalFileFieldName != "" {
opts.PortalFileFieldName = portalFileFieldName
}
Expand All @@ -216,7 +223,7 @@ func skynetuploadcmd(sourcePath string) {
opts.SkykeyID = uploadSkykeyID
}

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

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

// Upload File
if !fi.IsDir() {
skylink, err = skynet.UploadFile(sourcePath, opts)
skylink, err = client.UploadFile(sourcePath, opts)
if err != nil {
return "", "file", errors.AddContext(err, "Unable to upload file")
}
return skylink, "file", nil
}

// Upload directory
skylink, err = skynet.UploadDirectory(sourcePath, opts)
skylink, err = client.UploadDirectory(sourcePath, opts)
if err != nil {
return "", "directory", errors.AddContext(err, "Unable to upload directory")
}
return skylink, "directory", nil
}

// getCommonOptions gets options from the persistent root flags that are common
// to all commands.
func getCommonOptions(opts skynet.Options) skynet.Options {
if skynetPortal != "" {
opts.PortalURL = skynetPortal
}
// 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{}
if endpointPath != "" {
opts.EndpointPath = endpointPath
}
Expand All @@ -272,5 +278,8 @@ func getCommonOptions(opts skynet.Options) skynet.Options {
if customUserAgent != "" {
opts.CustomUserAgent = customUserAgent
}
return opts
// 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
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ module github.com/NebulousLabs/skynet-cli
go 1.13

require (
github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66
github.com/NebulousLabs/go-skynet/v2 v2.0.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
gitlab.com/NebulousLabs/errors v0.0.0-20171229012116-7ead97ef90b8
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
19 changes: 2 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NebulousLabs/go-skynet v0.0.0-20200615123241-9b30d4ffd492 h1:KPJHmIBb5szkxU4acjpLVFQxPIU/vfjhghAYxEixuNU=
github.com/NebulousLabs/go-skynet v0.0.0-20200615123241-9b30d4ffd492/go.mod h1:uOpyXOndZfQYn/hIdGgR0DJCK2I4uz+NNmXtxlaCUyg=
github.com/NebulousLabs/go-skynet v0.0.0-20200721163935-c56e138c1a03 h1:E+UMrK7thvS73wxDhTgE35fxN0hSCT6KBI2vWao4zj8=
github.com/NebulousLabs/go-skynet v0.0.0-20200721163935-c56e138c1a03/go.mod h1:6vr7Kb2aMpGrAuLmZ2LOtuqLusO1ISRglRXDv+vkmdI=
github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66 h1:dboQMHW8YhTQcsjnBB/s4ZPXk/O1Jf8R6O9BaStll2o=
github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66/go.mod h1:6vr7Kb2aMpGrAuLmZ2LOtuqLusO1ISRglRXDv+vkmdI=
github.com/NebulousLabs/go-skynet/v2 v2.0.0 h1:hPgml8Qc5RalldibBZ9p66Oggoud45OIZZnut9pWNUo=
github.com/NebulousLabs/go-skynet/v2 v2.0.0/go.mod h1:uhGD1M7Qe1nXsnqRD90B5CJVgjqSqwJUmDosgAn4CdQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -120,42 +116,31 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down

0 comments on commit 99ff022

Please sign in to comment.