Repository: incubator-htrace Updated Branches: refs/heads/master 220a93e65 -> 47b889c4c
HTRACE-327: improve htraced command-line parsing and add version command Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/47b889c4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/47b889c4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/47b889c4 Branch: refs/heads/master Commit: 47b889c4c1b37649d0351a98c18c40cf40adb4df Parents: 220a93e Author: Colin P. Mccabe <[email protected]> Authored: Mon Dec 14 07:56:23 2015 -0800 Committer: Colin P. Mccabe <[email protected]> Committed: Mon Dec 14 07:56:23 2015 -0800 ---------------------------------------------------------------------- .../go/src/org/apache/htrace/htraced/htraced.go | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/47b889c4/htrace-htraced/go/src/org/apache/htrace/htraced/htraced.go ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/htraced.go b/htrace-htraced/go/src/org/apache/htrace/htraced/htraced.go index fdd2745..35ee753 100644 --- a/htrace-htraced/go/src/org/apache/htrace/htraced/htraced.go +++ b/htrace-htraced/go/src/org/apache/htrace/htraced/htraced.go @@ -23,13 +23,13 @@ import ( "bufio" "encoding/json" "fmt" + "github.com/alecthomas/kingpin" "github.com/jmhodges/levigo" "net" "org/apache/htrace/common" "org/apache/htrace/conf" "os" "runtime" - "strings" "time" ) @@ -48,7 +48,7 @@ Usage: -Dk=v: set configuration key 'k' to value 'v' For example -Dweb.address=127.0.0.1:8080 sets the web address to localhost, -port 8080. +port 8080. -Dlog.level=DEBUG will set the default log level to DEBUG. -Dk: set configuration key 'k' to 'true' @@ -59,17 +59,22 @@ of setting configuration when launching the daemon. ` func main() { - for idx := range os.Args { - arg := os.Args[idx] - if strings.HasPrefix(arg, "--h") || strings.HasPrefix(arg, "-h") { - fmt.Fprintf(os.Stderr, USAGE) - os.Exit(0) - } - } - // Load the htraced configuration. + // This also parses the -Dfoo=bar command line arguments and removes them + // from os.Argv. cnf, cnfLog := conf.LoadApplicationConfig("htraced.") + // Parse the remaining command-line arguments. + app := kingpin.New(os.Args[0], USAGE) + version := app.Command("version", "Print server version and exit.") + cmd := kingpin.MustParse(app.Parse(os.Args[1:])) + + // Handle the "version" command-line argument. + if cmd == version.FullCommand() { + fmt.Printf("Running htraced %s [%s].\n", RELEASE_VERSION, GIT_VERSION) + os.Exit(0) + } + // Open the HTTP port. // We want to do this first, before initializing the datastore or setting up // logging. That way, if someone accidentally starts two daemons with the
