forked from hauler-dev/hauler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
126 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/rancherfederal/hauler/pkg/version" | ||
) | ||
|
||
func addVersion(parent *cobra.Command) { | ||
var json bool | ||
|
||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Print current hauler version", | ||
Long: "Print current hauler version", | ||
Aliases: []string{"v"}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
v := version.GetVersionInfo() | ||
response := v.String() | ||
if json { | ||
data, err := v.JSONString() | ||
if err != nil { | ||
return err | ||
} | ||
response = data | ||
} | ||
fmt.Print(response) | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&json, "json", false, "toggle output in JSON") | ||
|
||
parent.AddCommand(cmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package version | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"path" | ||
"runtime" | ||
"strings" | ||
"text/tabwriter" | ||
) | ||
|
||
var ( | ||
GitVersion = "devel" | ||
commit = "unknown" | ||
buildDate = "unknown" | ||
) | ||
|
||
type Info struct { | ||
GitVersion string | ||
GitCommit string | ||
BuildDate string | ||
|
||
GoVersion string | ||
Compiler string | ||
Platform string | ||
} | ||
|
||
func GetVersionInfo() Info { | ||
return Info{ | ||
GitVersion: GitVersion, | ||
GitCommit: commit, | ||
BuildDate: buildDate, | ||
|
||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: path.Join(runtime.GOOS, runtime.GOARCH), | ||
} | ||
} | ||
|
||
func (i Info) String() string { | ||
b := strings.Builder{} | ||
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0) | ||
|
||
fmt.Fprintf(w, "GitVersion:\t%s\n", i.GitVersion) | ||
fmt.Fprintf(w, "GitCommit:\t%s\n", i.GitCommit) | ||
fmt.Fprintf(w, "BuildDate:\t%s\n", i.BuildDate) | ||
fmt.Fprintf(w, "GoVersion:\t%s\n", i.GoVersion) | ||
fmt.Fprintf(w, "Compiler:\t%s\n", i.Compiler) | ||
fmt.Fprintf(w, "Platform:\t%s\n", i.Platform) | ||
|
||
w.Flush() | ||
return b.String() | ||
} | ||
|
||
func (i Info) JSONString() (string, error) { | ||
b, err := json.MarshalIndent(i, "", " ") | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(b), nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.