diff --git a/tools/rw-benchmark/plot_data.go b/tools/rw-benchmark/plot_data.go index d3fe721c544b..63e8b7f7a7d3 100644 --- a/tools/rw-benchmark/plot_data.go +++ b/tools/rw-benchmark/plot_data.go @@ -46,6 +46,17 @@ Additional options: // parseParams parses all the options and arguments func parseParams(args ...string) (legends []string, csvFiles []string, outFile string, err error) { + // Require at least one argument. + // + // Usually when users use a tool in the first time, they don't know how + // to use it, so usually they just execute the command without any + // arguments. So it would be better to display the usage instead of an + // error message in this case. + if len(args) == 0 { + fmt.Fprintln(os.Stderr, usage()) + os.Exit(2) + } + var ( help bool legend string @@ -395,19 +406,25 @@ func main() { legends, csvFiles, outFile, err := parseParams(os.Args[1:]...) if err != nil { fmt.Fprintf(os.Stderr, "Failed to parse the parameters: %v\n", err) - os.Exit(1) + exit() } // load data of CSV files (1 or 2 files are expected) dataMap, err := loadData(csvFiles...) if err != nil { fmt.Fprintf(os.Stderr, "Failed to load data file(s): %v\n", err) - os.Exit(1) + exit() } // render all data in one HTML page if err = renderPage(legends, dataMap, outFile); err != nil { fmt.Fprintf(os.Stderr, "Failed to render data to HTML page: %v\n", err) - os.Exit(1) + exit() } } + +func exit() { + fmt.Fprintf(os.Stderr, "\n") + fmt.Fprintf(os.Stderr, "Run `rw-benchmark -h` to print usage info.\n") + os.Exit(1) +}