Skip to content

Commit

Permalink
Simplify version printing code (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiczko authored Dec 4, 2020
1 parent 2983d74 commit d48e6b7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 39 deletions.
19 changes: 0 additions & 19 deletions cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ type Config struct {
Logger micrologger.Logger
Stderr io.Writer
Stdout io.Writer

Version string
BinaryName string
GitCommit string
Source string
}

func New(config Config) (*cobra.Command, error) {
Expand All @@ -35,16 +30,6 @@ func New(config Config) (*cobra.Command, error) {
config.Stdout = os.Stdout
}

if config.Version == "" {
return nil, microerror.Maskf(invalidConfigError, "%T.Version must not be empty", config)
}
if config.GitCommit == "" {
return nil, microerror.Maskf(invalidConfigError, "%T.GitCommit must not be empty", config)
}
if config.Source == "" {
return nil, microerror.Maskf(invalidConfigError, "%T.Source must not be empty", config)
}

var err error

var bootstrapCmd *cobra.Command
Expand All @@ -67,10 +52,6 @@ func New(config Config) (*cobra.Command, error) {
Logger: config.Logger,
Stderr: config.Stderr,
Stdout: config.Stdout,

GitCommit: config.GitCommit,
Source: config.Source,
Version: config.Version,
}

versionCmd, err = version.New(c)
Expand Down
8 changes: 0 additions & 8 deletions cmd/version/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ type Config struct {
Logger micrologger.Logger
Stderr io.Writer
Stdout io.Writer

GitCommit string
Source string
Version string
}

func New(config Config) (*cobra.Command, error) {
Expand All @@ -42,10 +38,6 @@ func New(config Config) (*cobra.Command, error) {
logger: config.Logger,
stderr: config.Stderr,
stdout: config.Stdout,

gitCommit: config.GitCommit,
source: config.Source,
version: config.Version,
}

c := &cobra.Command{
Expand Down
12 changes: 5 additions & 7 deletions cmd/version/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import (
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/spf13/cobra"

"github.com/giantswarm/apptestctl/pkg/project"
)

type runner struct {
flag *flag
logger micrologger.Logger
stdout io.Writer
stderr io.Writer

gitCommit string
source string
version string
}

func (r *runner) Run(cmd *cobra.Command, args []string) error {
Expand All @@ -39,11 +37,11 @@ func (r *runner) Run(cmd *cobra.Command, args []string) error {
}

func (r *runner) run(ctx context.Context, cmd *cobra.Command, args []string) error {
fmt.Fprintf(r.stdout, "Version: %s\n", r.version)
fmt.Fprintf(r.stdout, "Git Commit: %s\n", r.gitCommit)
fmt.Fprintf(r.stdout, "Version: %s\n", project.Version())
fmt.Fprintf(r.stdout, "Git Commit: %s\n", project.GitSHA())
fmt.Fprintf(r.stdout, "Go Version: %s\n", runtime.Version())
fmt.Fprintf(r.stdout, "OS / Arch: %s / %s\n", runtime.GOOS, runtime.GOARCH)
fmt.Fprintf(r.stdout, "Source: %s\n", r.source)
fmt.Fprintf(r.stdout, "Source: %s\n", project.Source())

return nil
}
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/spf13/cobra"

"github.com/giantswarm/apptestctl/cmd"
"github.com/giantswarm/apptestctl/pkg/project"
)

func main() {
Expand All @@ -36,10 +35,6 @@ func mainE(ctx context.Context) error {
{
c := cmd.Config{
Logger: logger,

GitCommit: project.GitSHA(),
Source: project.Source(),
Version: project.Version(),
}

rootCommand, err = cmd.New(c)
Expand Down

0 comments on commit d48e6b7

Please sign in to comment.