Skip to content

Commit

Permalink
feat: add version subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
moooofly committed Feb 7, 2019
1 parent fc47fb7 commit 2d2ba4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"

homedir "github.com/mitchellh/go-homedir"
"github.com/moooofly/harborctl/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -37,6 +38,16 @@ var rootCmd = &cobra.Command{
Use: "harborctl",
Short: "A CLI tool for the Docker Registry Harbor.",
Long: `This project offer a command-line interface to the Harbor API, you can use it to manager your users, projects, repositories, etc.`,
Version: fmt.Sprintf("%s\n%s\n| % -20s | % -40s |\n| % -20s | % -40s |\n| % -20s | % -40s |\n| % -20s | % -40s |\n| % -20s | % -40s |\n| % -20s | % -40s |\n%s\n",
utils.Logo,
utils.Mark,
"Client Version", utils.ClientVersion,
"Go Version", utils.GoVersion,
"UTC Build Time", utils.UTCBuildTime,
"Git Branch", utils.GitBranch,
"Git Tag", utils.GitTag,
"Git Hash", utils.GitHash,
utils.Mark),
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Expand All @@ -57,14 +68,14 @@ func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().StringVarP(&address, "address", "", "localhost", "The address of target endpoint.")
viper.BindPFlag("address", rootCmd.PersistentFlags().Lookup("address"))
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/, working dir (.), and ./conf dir)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

rootCmd.PersistentFlags().StringVarP(&address, "address", "", "localhost", "The address of target endpoint.")
viper.BindPFlag("address", rootCmd.PersistentFlags().Lookup("address"))
rootCmd.Flags().BoolP("version", "v", false, "Print version information and quit.")
rootCmd.SetVersionTemplate(`{{printf "%s\n" .Version}}`)
}

// initConfig reads in config file and ENV variables if set.
Expand Down
12 changes: 12 additions & 0 deletions utils/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ package utils

import "errors"

const Logo = `
__ __ ____ ____ ____ ___ ____ __ ______ _
| | | / || \ | \ / \ | \ / ] || |
| | || o || D )| o )| || D ) / /| || |
| _ || || / | || O || / / / |_| |_|| |___
| | || _ || \ | O || || \ / \_ | | | |
| | || | || . \| || || . \\ | | | | |
|__|__||__|__||__|\_||_____| \___/ |__|\_| \____| |__| |_____|
`

const Mark = `+----------------------+------------------------------------------+`

// These variables are populated via the Go linker.
var (
UTCBuildTime = "unknown"
Expand Down

0 comments on commit 2d2ba4b

Please sign in to comment.