Skip to content

Commit

Permalink
pkg: cmd: remove "version" command from pkg
Browse files Browse the repository at this point in the history
The "version" command needs the non-exported `pkg/version`.
his makes the `commands` pkg unusable otuside this project,
that is violating the original design.

We need to untie the `commands` pkg from the unshipped `version` pkg;
it is still correct to NOT ship the latter just yet.

The version command is tied to this source tree, so it
makes sense to move it `cmd`, which we do in this patch.

No expected changes in behaviour.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Jul 1, 2022
1 parent 0010179 commit e67b4aa
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 e67b4aa

Please sign in to comment.