Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,9 @@ golint:

party:
party -c -d=vendor


.PHONY: convey
convey:
go get github.com/smartystreets/goconvey
goconvey -cover -port=9042 -workDir="$(realpath .)/pkg" -depth=-1
5 changes: 4 additions & 1 deletion cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ func main() {
}
cmd.API = api
}
cmd.Exec(cmd, cmd.Flag.Args())
err = cmd.Exec(cmd, cmd.Flag.Args())
if err != nil {
log.Fatalf("Cannot execute '%s': %v", cmd.Name(), err)
}
if cmd.API != nil {
cmd.API.Sync()
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package api

import (
"testing"

. "github.com/scaleway/scaleway-cli/vendor/github.com/smartystreets/goconvey/convey"
)

func TestNewScalewayAPI(t *testing.T) {
Convey("Testing NewScalewayAPI()", t, func() {
api, err := NewScalewayAPI("http://api-endpoint.com", "http://account-endpoint.com", "my-organization", "my-token")
So(err, ShouldBeNil)
So(api, ShouldNotBeNil)
So(api.ComputeAPI, ShouldEqual, "http://api-endpoint.com")
So(api.AccountAPI, ShouldEqual, "http://account-endpoint.com")
So(api.Token, ShouldEqual, "my-token")
So(api.Organization, ShouldEqual, "my-organization")
So(api.Cache, ShouldNotBeNil)
So(api.client, ShouldNotBeNil)
So(api.anonuuid, ShouldNotBeNil)
})
}
3 changes: 2 additions & 1 deletion pkg/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package api
import (
"encoding/json"
"fmt"
"github.com/scaleway/scaleway-cli/pkg/utils"
"os"

"github.com/scaleway/scaleway-cli/pkg/utils"
)

// Config is a Scaleway CLI configuration file
Expand Down
14 changes: 4 additions & 10 deletions pkg/cli/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdAttach = &Command{
Exec: cmdExecAttach,
Exec: runAttach,
UsageLine: "attach [OPTIONS] SERVER",
Description: "Attach to a server serial console",
Help: "Attach to a running server serial console.",
Expand All @@ -30,7 +27,7 @@ func init() {
var attachHelp bool // -h, --help flag
var attachNoStdin bool // --no-stdin flag

func cmdExecAttach(cmd *Command, rawArgs []string) {
func runAttach(cmd *Command, rawArgs []string) error {
if attachHelp {
cmd.PrintUsage()
}
Expand All @@ -43,8 +40,5 @@ func cmdExecAttach(cmd *Command, rawArgs []string) {
Server: rawArgs[0],
}
ctx := cmd.GetContext(rawArgs)
err := commands.RunAttach(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'attach': %v", err)
}
return commands.RunAttach(ctx, args)
}
2 changes: 1 addition & 1 deletion pkg/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// Command contains everything needed by the cli main loop to calls the workflow, display help and usage, and the context
type Command struct {
// Exec executes the command
Exec func(cmd *Command, args []string)
Exec func(cmd *Command, args []string) error

// Usage is the one-line usage message.
UsageLine string
Expand Down
21 changes: 21 additions & 0 deletions pkg/cli/command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cli

import (
"testing"

. "github.com/scaleway/scaleway-cli/vendor/github.com/smartystreets/goconvey/convey"
)

func TestCommand_Name(t *testing.T) {
Convey("Testing Command.Name()", t, func() {
command := Command{
UsageLine: "top [OPTIONS] SERVER",
}
So(command.Name(), ShouldEqual, "top")

command = Command{
UsageLine: "top",
}
So(command.Name(), ShouldEqual, "top")
})
}
14 changes: 4 additions & 10 deletions pkg/cli/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdCommit = &Command{
Exec: cmdExecCommit,
Exec: runCommit,
UsageLine: "commit [OPTIONS] SERVER [NAME]",
Description: "Create a new snapshot from a server's volume",
Help: "Create a new snapshot from a server's volume.",
Expand All @@ -29,7 +26,7 @@ func init() {
var commitVolume int // -v, --volume flag
var commitHelp bool // -h, --help flag

func cmdExecCommit(cmd *Command, rawArgs []string) {
func runCommit(cmd *Command, rawArgs []string) error {
if commitHelp {
cmd.PrintUsage()
}
Expand All @@ -47,8 +44,5 @@ func cmdExecCommit(cmd *Command, rawArgs []string) {
}

ctx := cmd.GetContext(rawArgs)
err := commands.RunCommit(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'commit': %v", err)
}
return commands.RunCommit(ctx, args)
}
13 changes: 3 additions & 10 deletions pkg/cli/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdCp = &Command{
Exec: runCp,
Expand Down Expand Up @@ -40,7 +37,7 @@ func init() {
var cpHelp bool // -h, --help flag
var cpGateway string // -g, --gateway flag

func runCp(cmd *Command, rawArgs []string) {
func runCp(cmd *Command, rawArgs []string) error {
if cpHelp {
cmd.PrintUsage()
}
Expand All @@ -54,9 +51,5 @@ func runCp(cmd *Command, rawArgs []string) {
Destination: rawArgs[1],
}
ctx := cmd.GetContext(rawArgs)
err := commands.RunCp(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'cp': %v", err)
}

return commands.RunCp(ctx, args)
}
8 changes: 2 additions & 6 deletions pkg/cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)

var cmdCreate = &Command{
Expand Down Expand Up @@ -43,7 +42,7 @@ var createVolume string // -v, --volume flag
var createHelp bool // -h, --help flag
var createTmpSSHKey bool // --tmp-ssh-key flag

func runCreate(cmd *Command, rawArgs []string) {
func runCreate(cmd *Command, rawArgs []string) error {
if createHelp {
cmd.PrintUsage()
}
Expand All @@ -65,8 +64,5 @@ func runCreate(cmd *Command, rawArgs []string) {
args.Volumes = strings.Split(runCreateVolume, " ")
}
ctx := cmd.GetContext(rawArgs)
err := commands.RunCreate(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'create': %v", err)
}
return commands.RunCreate(ctx, args)
}
14 changes: 4 additions & 10 deletions pkg/cli/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdEvents = &Command{
Exec: cmdExecEvents,
Exec: runEvents,
UsageLine: "events [OPTIONS]",
Description: "Get real time events from the API",
Help: "Get real time events from the API.",
Expand All @@ -23,7 +20,7 @@ func init() {
// Flags
var eventsHelp bool // -h, --help flag

func cmdExecEvents(cmd *Command, rawArgs []string) {
func runEvents(cmd *Command, rawArgs []string) error {
if eventsHelp {
cmd.PrintUsage()
}
Expand All @@ -33,8 +30,5 @@ func cmdExecEvents(cmd *Command, rawArgs []string) {

args := commands.EventsArgs{}
ctx := cmd.GetContext(rawArgs)
err := commands.RunEvents(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'events': %v", err)
}
return commands.RunEvents(ctx, args)
}
14 changes: 4 additions & 10 deletions pkg/cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdExec = &Command{
Exec: cmdExecExec,
Exec: runExec,
UsageLine: "exec [OPTIONS] SERVER [COMMAND] [ARGS...]",
Description: "Run a command on a running server",
Help: "Run a command on a running server.",
Expand Down Expand Up @@ -41,7 +38,7 @@ var execTimeout float64 // -T flag
var execHelp bool // -h, --help flag
var execGateway string // -g, --gateway flag

func cmdExecExec(cmd *Command, rawArgs []string) {
func runExec(cmd *Command, rawArgs []string) error {
if execHelp {
cmd.PrintUsage()
}
Expand All @@ -57,8 +54,5 @@ func cmdExecExec(cmd *Command, rawArgs []string) {
Command: rawArgs[1:],
}
ctx := cmd.GetContext(rawArgs)
err := commands.RunExec(ctx, args)
if err != nil {
logrus.Fatalf("Cannot exec 'exec': %v", err)
}
return commands.RunExec(ctx, args)
}
5 changes: 3 additions & 2 deletions pkg/cli/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Commands:
Run 'scw COMMAND --help' for more information on a command.
`

func runHelp(cmd *Command, args []string) {
func runHelp(cmd *Command, args []string) error {
if waitHelp {
cmd.PrintUsage()
}
Expand All @@ -73,7 +73,8 @@ func runHelp(cmd *Command, args []string) {
t := template.New("top")
template.Must(t.Parse(helpTemplate))
if err := t.Execute(os.Stdout, Commands); err != nil {
panic(err)
return err
}
}
return nil
}
12 changes: 3 additions & 9 deletions pkg/cli/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdHistory = &Command{
Exec: runHistory,
Expand All @@ -27,7 +24,7 @@ var historyNoTrunc bool // --no-trunc flag
var historyQuiet bool // -q, --quiet flag
var historyHelp bool // -h, --help flag

func runHistory(cmd *Command, rawArgs []string) {
func runHistory(cmd *Command, rawArgs []string) error {
if historyHelp {
cmd.PrintUsage()
}
Expand All @@ -41,8 +38,5 @@ func runHistory(cmd *Command, rawArgs []string) {
Image: rawArgs[0],
}
ctx := cmd.GetContext(rawArgs)
err := commands.RunHistory(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'history': %v", err)
}
return commands.RunHistory(ctx, args)
}
12 changes: 3 additions & 9 deletions pkg/cli/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdImages = &Command{
Exec: runImages,
Expand All @@ -29,7 +26,7 @@ var imagesQ bool // -q flag
var imagesNoTrunc bool // -no-trunc flag
var imagesHelp bool // -h, --help flag

func runImages(cmd *Command, rawArgs []string) {
func runImages(cmd *Command, rawArgs []string) error {
if imagesHelp {
cmd.PrintUsage()
}
Expand All @@ -43,8 +40,5 @@ func runImages(cmd *Command, rawArgs []string) {
NoTrunc: imagesNoTrunc,
}
ctx := cmd.GetContext(rawArgs)
err := commands.RunImages(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'images': %v", err)
}
return commands.RunImages(ctx, args)
}
12 changes: 3 additions & 9 deletions pkg/cli/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

package cli

import (
"github.com/scaleway/scaleway-cli/pkg/commands"
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
import "github.com/scaleway/scaleway-cli/pkg/commands"

var cmdInfo = &Command{
Exec: runInfo,
Expand All @@ -23,7 +20,7 @@ func init() {
// Flags
var infoHelp bool // -h, --help flag

func runInfo(cmd *Command, rawArgs []string) {
func runInfo(cmd *Command, rawArgs []string) error {
if infoHelp {
cmd.PrintUsage()
}
Expand All @@ -33,8 +30,5 @@ func runInfo(cmd *Command, rawArgs []string) {

args := commands.InfoArgs{}
ctx := cmd.GetContext(rawArgs)
err := commands.RunInfo(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'info': %v", err)
}
return commands.RunInfo(ctx, args)
}
Loading