-
Notifications
You must be signed in to change notification settings - Fork 2.2k
version: Add a version command #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -760,6 +760,7 @@ _runc() { | |
| start | ||
| state | ||
| update | ||
| version | ||
| help | ||
| h | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # NAME | ||
| runc version - output the runtime version | ||
|
|
||
| # SYNOPSIS | ||
| runc version | ||
|
|
||
| Write version information to stdout and exit. | ||
|
|
||
| # DESCRIPTION | ||
| The version command writes version information for runc and the | ||
| supported spec release. This information is also exposed through | ||
| `runc --version`, and callers can use whichever is more convenient for | ||
| them. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/opencontainers/runtime-spec/specs-go" | ||
| "github.com/urfave/cli" | ||
| ) | ||
|
|
||
| // version will be populated by the Makefile, read from | ||
| // VERSION file of the source code. | ||
| var version = "" | ||
|
|
||
| // gitCommit will be the hash that the binary was built from | ||
| // and will be populated by the Makefile | ||
| var gitCommit = "" | ||
|
|
||
| var versionCommand = cli.Command{ | ||
| Name: "version", | ||
| Usage: "output the runtime version", | ||
| Description: `The version command outputs the runtime version.`, | ||
| Action: printVersion, | ||
| } | ||
|
|
||
| func printVersion(context *cli.Context) (err error) { | ||
| if version == "" { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you just do the same logic with the slice and strings.Join so we don't have all these verbose if else
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Tue, Aug 23, 2016 at 10:46:25AM -0700, Michael Crosby wrote:
The same logic as what? This check is for “someone build this
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like we had in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Tue, Aug 23, 2016 at 11:09:30AM -0700, Michael Crosby wrote:
The code I removed from main.go was:
That's building the output string in memory and using Join to store it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that's what he's asking for, build a string in memory then output it. |
||
| _, err = fmt.Print("runc unknown\n") | ||
| } else { | ||
| _, err = fmt.Printf("runc %s\n", version) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if gitCommit != "" { | ||
| _, err = fmt.Printf("commit: %s\n", gitCommit) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| _, err = fmt.Printf("spec: %s\n", specs.Version) | ||
| return err | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this entire function's contents are poorly written and is bad quality. No where else in our code do we use these functions on
os.Stdoutand all the branches with if/else are just bad. It needs to be improvedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm replacing the
os.Stdout.WriteStringcalls withfmt.Print*calls.Most of the
ifblocks are for error checking, and I don't know how to avoid that in Go. The onlyelseis to cover “have/don't-have a version?”, and I think we want to cover both sides of that. Besides error checking and version presence, the only other conditional is for “have a Git commit?”, and I think we want to cover that too. Do you have any conditionals you'd like to see dropped?