Added migrations.d
This commit is contained in:
@@ -1,22 +1,76 @@
|
||||
package apply
|
||||
package version
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
buildInfo "example.com/monok8s/pkg/buildinfo"
|
||||
buildinfo "example.com/monok8s/pkg/buildinfo"
|
||||
)
|
||||
|
||||
type versionInfo struct {
|
||||
Version string `json:"version"`
|
||||
GitRevision string `json:"gitRevision"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
KubeVersion string `json:"kubernetesVersion"`
|
||||
}
|
||||
|
||||
func NewCmdVersion() *cobra.Command {
|
||||
var (
|
||||
shortOutput bool
|
||||
jsonOutput bool
|
||||
kubernetesOutput bool
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version information",
|
||||
Short: "Print version information",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
info := versionInfo{
|
||||
Version: buildinfo.Version,
|
||||
GitRevision: buildinfo.GitRevision,
|
||||
Timestamp: buildinfo.Timestamp,
|
||||
KubeVersion: buildinfo.KubeVersion,
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintln(cmd.OutOrStdout(), fmt.Sprintf("%s %s(%s)", buildInfo.Version, buildInfo.GitRevision, buildInfo.Timestamp))
|
||||
return err
|
||||
out := cmd.OutOrStdout()
|
||||
|
||||
switch {
|
||||
case jsonOutput:
|
||||
enc := json.NewEncoder(out)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(info)
|
||||
|
||||
case kubernetesOutput:
|
||||
_, err := fmt.Fprintln(out, info.KubeVersion)
|
||||
return err
|
||||
|
||||
case shortOutput:
|
||||
_, err := fmt.Fprintln(out, info.Version)
|
||||
return err
|
||||
|
||||
default:
|
||||
_, err := fmt.Fprintf(
|
||||
out,
|
||||
"Version: %s\nGit commit: %s\nBuilt at: %s\nKubernetes: %s\n",
|
||||
info.Version,
|
||||
info.GitRevision,
|
||||
info.Timestamp,
|
||||
info.KubeVersion,
|
||||
)
|
||||
return err
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVar(&shortOutput, "short", false, "Show only the application version")
|
||||
flags.BoolVar(&jsonOutput, "json", false, "Show version information as JSON")
|
||||
flags.BoolVarP(&kubernetesOutput, "kubernetes", "k", false, "Show only the Kubernetes version this binary was built for")
|
||||
|
||||
cmd.MarkFlagsMutuallyExclusive("short", "json", "kubernetes")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user