-
Notifications
You must be signed in to change notification settings - Fork 9
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
4 changed files
with
98 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
flagJSON = "json" | ||
) | ||
|
||
func jsonFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command { | ||
cmd.Flags().BoolP(flagJSON, "j", false, "returns the response in json format") | ||
if err := v.BindPFlag(flagJSON, cmd.Flags().Lookup(flagJSON)); err != nil { | ||
panic(err) | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/spf13/cobra" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
var ( | ||
// Version defines the application version (defined at compile time) | ||
Version = "" | ||
Commit = "" | ||
Dirty = "" | ||
) | ||
|
||
type versionInfo struct { | ||
Version string `json:"version" yaml:"version"` | ||
Commit string `json:"commit" yaml:"commit"` | ||
Go string `json:"go" yaml:"go"` | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the relayer version info", | ||
RunE: getVersionCmd, | ||
} | ||
|
||
func getVersionCmd(cmd *cobra.Command, args []string) error { | ||
// jsn, err := cmd.Flags().GetBool(flagJSON) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
commit := Commit | ||
if Dirty != "0" { | ||
commit += " (dirty)" | ||
} | ||
|
||
verInfo := versionInfo{ | ||
Version: Version, | ||
Commit: commit, | ||
Go: fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH), | ||
} | ||
|
||
bz, err := yaml.Marshal(&verInfo) | ||
|
||
fmt.Fprintln(cmd.OutOrStdout(), string(bz)) | ||
return err | ||
} |