-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from nkryuchkov/feature/version
Version command
- Loading branch information
Showing
15 changed files
with
141 additions
and
22 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
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,27 @@ | ||
package node | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
RootCmd.AddCommand(buildInfoCmd) | ||
} | ||
|
||
var buildInfoCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Obtains version and build info of the node", | ||
Run: func(_ *cobra.Command, _ []string) { | ||
client := rpcClient() | ||
summary, err := client.Summary() | ||
if err != nil { | ||
log.Fatal("Failed to connect:", err) | ||
} | ||
|
||
if _, err := summary.BuildInfo.WriteTo(os.Stdout); err != nil { | ||
log.Fatal("Failed to output build info:", err) | ||
} | ||
}, | ||
} |
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,52 @@ | ||
package buildinfo | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
) | ||
|
||
const unknown = "unknown" | ||
|
||
var ( | ||
version = unknown | ||
commit = unknown | ||
date = unknown | ||
) | ||
|
||
// Version returns version from git describe. | ||
func Version() string { | ||
return version | ||
} | ||
|
||
// Commit returns commit hash. | ||
func Commit() string { | ||
return commit | ||
} | ||
|
||
// Date returns date of build in RFC3339 format. | ||
func Date() string { | ||
return date | ||
} | ||
|
||
// Get returns build info summary. | ||
func Get() *Info { | ||
return &Info{ | ||
Version: Version(), | ||
Commit: Commit(), | ||
Date: Date(), | ||
} | ||
} | ||
|
||
// Info is build info summary. | ||
type Info struct { | ||
Version string `json:"version"` | ||
Commit string `json:"commit"` | ||
Date string `json:"date"` | ||
} | ||
|
||
// WriteTo writes build info summary to io.Writer. | ||
func (info *Info) WriteTo(w io.Writer) (int64, error) { | ||
msg := fmt.Sprintf("Version %q built on %q agaist commit %q\n", info.Version, info.Date, info.Commit) | ||
n, err := w.Write([]byte(msg)) | ||
return int64(n), err | ||
} |
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