Skip to content

Commit

Permalink
Merge pull request k8stopologyawareschedwg#102 from fromanirh/extract…
Browse files Browse the repository at this point in the history
…-version

pkg: cmd: remove "version" command from pkg
  • Loading branch information
ffromani authored Jul 1, 2022
2 parents 0010179 + e67b4aa commit 137afff
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 54 deletions.
32 changes: 31 additions & 1 deletion cmd/deployer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,41 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/k8stopologyawareschedwg/deployer/pkg/commands"
deployerversion "github.com/k8stopologyawareschedwg/deployer/pkg/version"
)

type versionOptions struct {
fullOutput bool
hashOnly bool
}

func NewVersionCommand(commonOpts *commands.CommonOptions) *cobra.Command {
opts := versionOptions{}
version := &cobra.Command{
Use: "version",
Short: "emit the version and exits succesfully",
RunE: func(cmd *cobra.Command, args []string) error {
if opts.hashOnly {
fmt.Printf("%s\n", deployerversion.GitCommit)
} else if opts.fullOutput {
fmt.Printf("%s-%s\n", deployerversion.GitVersion, deployerversion.GitCommit[:9])
} else {
fmt.Printf("%s\n", deployerversion.GitVersion)
}
return nil
},
Args: cobra.NoArgs,
}
version.PersistentFlags().BoolVar(&opts.fullOutput, "full", false, "emit version and git hash.")
version.PersistentFlags().BoolVar(&opts.hashOnly, "hash", false, "emit only the git hash.")
return version
}

func main() {
root := commands.NewRootCommand()
root := commands.NewRootCommand(NewVersionCommand)
if err := root.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func NewRootCommand(extraCmds ...NewCommandFunc) *cobra.Command {
NewRemoveCommand(commonOpts),
NewSetupCommand(commonOpts),
NewDetectCommand(commonOpts),
NewVersionCommand(commonOpts),
NewImagesCommand(commonOpts),
)
for _, extraCmd := range extraCmds {
Expand Down
52 changes: 0 additions & 52 deletions pkg/commands/version.go

This file was deleted.

0 comments on commit 137afff

Please sign in to comment.