Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
Better version command
Browse files Browse the repository at this point in the history
Makes this a real command, listed in the help output.
  • Loading branch information
Edward Muller committed Nov 9, 2015
1 parent 1acc759 commit e9ac6d7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v28 2015/11/09

* Make `version` an actual command.

# v27 2015/11/06

* run command once during restore -v
Expand Down
7 changes: 1 addition & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"log"
"os"
"runtime"
"strings"
"text/template"
)
Expand Down Expand Up @@ -63,6 +62,7 @@ var commands = []*Command{
cmdRestore,
cmdUpdate,
cmdDiff,
cmdVersion,
}

func main() {
Expand All @@ -80,11 +80,6 @@ func main() {
return
}

if args[0] == "version" {
fmt.Printf("godep v%d (%s/%s/%s)\n", version, runtime.GOOS, runtime.GOARCH, runtime.Version())
return
}

for _, cmd := range commands {
if cmd.Name() == args[0] {
cmd.Flag.Usage = func() { cmd.UsageExit() }
Expand Down
21 changes: 20 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
package main

const version = 27
import (
"fmt"
"runtime"
)

const version = 28

var cmdVersion = &Command{
Usage: "version",
Short: "show version info",
Long: `
Displays the version of godep as well as the target OS, architecture and go runtime version.
`,
Run: runVersion,
}

func runVersion(cmd *Command, args []string) {
fmt.Printf("godep v%d (%s/%s/%s)\n", version, runtime.GOOS, runtime.GOARCH, runtime.Version())
}

3 comments on commit e9ac6d7

@dmitshur
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement!

Is it easy and desirable to make it so that running godep -version is also supported, in addition to godep version? If it's not too hard, I think that'd be nice.

It's pretty standard with command line tools, and also consistent with help command. Both of these work successfully:

  • godep help
  • godep -help

@kr
Copy link
Member

@kr kr commented on e9ac6d7 Nov 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the argument for having several ways to get help ('godep help', 'godep -help', 'godep -h', 'godep') because that's how you bootstrap your knowledge of the tool. If you can't find the help message, you're stuck!

As for all the other commands, none of them also act like a flag. I don't see why version should be special. Once you've read the help text, you know how to run all the commands, including version.

Also, if we're looking for an example to follow:

$ go -version
flag provided but not defined: -version
Go is a tool for managing Go source code.
…

@dmitshur
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kr I'm convinced, the current behavior is good. Thanks for providing rationale.

The answer to my question then is "no, it is not desirable."

Please sign in to comment.