Skip to content

Commit 09e7628

Browse files
committed
Refactored 'version' command (scaleway#80)
1 parent 317448a commit 09e7628

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

pkg/cli/version.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
package cli
66

77
import (
8-
"fmt"
9-
"runtime"
10-
11-
"github.com/scaleway/scaleway-cli/pkg/scwversion"
8+
"github.com/scaleway/scaleway-cli/pkg/commands"
9+
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
1210
)
1311

1412
var cmdVersion = &Command{
@@ -25,17 +23,18 @@ func init() {
2523
// Flags
2624
var versionHelp bool // -h, --help flag
2725

28-
func runVersion(cmd *Command, args []string) {
26+
func runVersion(cmd *Command, rawArgs []string) {
2927
if versionHelp {
3028
cmd.PrintUsage()
3129
}
32-
if len(args) != 0 {
30+
if len(rawArgs) != 0 {
3331
cmd.PrintShortUsage()
3432
}
3533

36-
fmt.Printf("Client version: %s\n", scwversion.VERSION)
37-
fmt.Printf("Go version (client): %s\n", runtime.Version())
38-
fmt.Printf("Git commit (client): %s\n", scwversion.GITCOMMIT)
39-
fmt.Printf("OS/Arch (client): %s/%s\n", runtime.GOOS, runtime.GOARCH)
40-
// FIXME: API version information
34+
args := commands.VersionArgs{}
35+
ctx := cmd.GetContext(rawArgs)
36+
err := commands.RunVersion(ctx, args)
37+
if err != nil {
38+
logrus.Fatalf("Cannot execute 'version': %v", err)
39+
}
4140
}

pkg/commands/version.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2015 Scaleway. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE.md file.
4+
5+
package commands
6+
7+
import (
8+
"fmt"
9+
"runtime"
10+
11+
"github.com/scaleway/scaleway-cli/pkg/scwversion"
12+
)
13+
14+
// VersionArgs are flags for the `RunVersion` function
15+
type VersionArgs struct{}
16+
17+
// RunVersion is the handler for 'scw version'
18+
func RunVersion(ctx CommandContext, args VersionArgs) error {
19+
fmt.Fprintf(ctx.Stdout, "Client version: %s\n", scwversion.VERSION)
20+
fmt.Fprintf(ctx.Stdout, "Go version (client): %s\n", runtime.Version())
21+
fmt.Fprintf(ctx.Stdout, "Git commit (client): %s\n", scwversion.GITCOMMIT)
22+
fmt.Fprintf(ctx.Stdout, "OS/Arch (client): %s/%s\n", runtime.GOOS, runtime.GOARCH)
23+
// FIXME: API version information
24+
25+
return nil
26+
}

0 commit comments

Comments
 (0)