Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1159 from SataQiu/move-version-pkg-20200103
Browse files Browse the repository at this point in the history
Refactor: make version subcommand as a public subcommand
  • Loading branch information
starnop committed Jan 4, 2020
2 parents 9aaea24 + 6d98b90 commit 48a4736
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 134 deletions.
1 change: 1 addition & 0 deletions cmd/dfdaemon/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func init() {

// add sub commands
rootCmd.AddCommand(cmd.NewGenDocCommand("dfdaemon"))
rootCmd.AddCommand(cmd.NewVersionCommand("dfdaemon"))
rootCmd.AddCommand(cmd.NewConfigCommand("dfdaemon", getDefaultConfig))
}

Expand Down
1 change: 1 addition & 0 deletions cmd/dfget/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var rootCmd = &cobra.Command{
func init() {
initFlags()
rootCmd.AddCommand(cmd.NewGenDocCommand("dfget"))
rootCmd.AddCommand(cmd.NewVersionCommand("dfget"))
}

// runDfget does some init operations and starts to download.
Expand Down
56 changes: 0 additions & 56 deletions cmd/dfget/app/version.go

This file was deleted.

1 change: 1 addition & 0 deletions cmd/supernode/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func init() {

// add sub commands
rootCmd.AddCommand(cmd.NewGenDocCommand("supernode"))
rootCmd.AddCommand(cmd.NewVersionCommand("supernode"))
rootCmd.AddCommand(cmd.NewConfigCommand("supernode", getDefaultConfig))
}

Expand Down
56 changes: 0 additions & 56 deletions cmd/supernode/app/version.go

This file was deleted.

45 changes: 23 additions & 22 deletions cmd/dfdaemon/app/version.go → pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,44 @@
* limitations under the License.
*/

package app
package cmd

import (
"github.com/dragonflyoss/Dragonfly/pkg/printer"
"fmt"

"github.com/dragonflyoss/Dragonfly/pkg/printer"
"github.com/dragonflyoss/Dragonfly/version"

"github.com/spf13/cobra"
)

// versionDescription is used to describe version command in detail and auto generate command doc.
var versionDescription = "Display the version and build information of Dragonfly dfdaemon, " +
// versionDescriptionTmp is used to describe version command in detail and auto generate command doc.
var versionDescriptionTmp = "Display the version and build information of Dragonfly %s, " +
"including GoVersion, OS, Arch, Version, BuildDate and GitCommit."

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show the current version of dfdaemon",
Long: versionDescription,
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
printer.Printf(version.Print("dfdaemon"))
return nil
},
Example: versionExample(),
}

func init() {
rootCmd.AddCommand(versionCmd)
// NewVersionCommand returns cobra.Command for "<component> version" command
func NewVersionCommand(name string) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: fmt.Sprintf("Show the current version of %s", name),
Long: fmt.Sprintf(versionDescriptionTmp, name),
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
printer.Printf(version.Print(name))
return nil
},
Example: versionExample(name),
}
return cmd
}

// versionExample shows examples in version command, and is used in auto-generated cli docs.
func versionExample() string {
return `dfdaemon version 0.4.1
func versionExample(name string) string {
return fmt.Sprintf(`%s version 0.4.1
Git commit: 6fd5c8f
Build date: 20190717-15:57:52
Go version: go1.12.10
OS/Arch: linux/amd64
`
`, name)
}

0 comments on commit 48a4736

Please sign in to comment.