Skip to content

Commit

Permalink
print usage info when no any argument provided
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 10, 2023
1 parent af2ac78 commit d908fe4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions tools/rw-benchmark/plot_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

0 comments on commit d908fe4

Please sign in to comment.