-
Notifications
You must be signed in to change notification settings - Fork 640
Provide more helpful error message and require input for every non-bool option. #519
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 1 commit
a9ea908
2a191ba
a2e56b4
f3c38ed
8563fb1
99ff77d
b6459a5
7483e19
a0929fd
2434176
68e3bcf
fee78be
71ef91f
c882260
54872a3
a7a638d
cebe0e4
cbe760c
091f3d9
05e747c
cfc1286
fc94335
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 |
|---|---|---|
|
|
@@ -215,7 +215,7 @@ var pprofVariables = variables{ | |
| "For memory profiles, report average memory per allocation.", | ||
| "For time-based profiles, report average time per event.")}, | ||
| "sample_index": &variable{stringKind, "", "", helpText( | ||
| "Sample value to report (0-based index or name)", | ||
| "Sample value to report (<x> is 0-based index or name)", | ||
| "Profiles contain multiple values per sample.", | ||
| "Use sample_index=i to select the ith value (starting at 0).")}, | ||
| "normalize": &variable{boolKind, "f", "", helpText( | ||
|
|
@@ -254,7 +254,7 @@ func usage(commandLine bool) string { | |
| prefix = "-" | ||
| } | ||
| fmtHelp := func(c, d string) string { | ||
| return fmt.Sprintf(" %-16s %s", c, strings.SplitN(d, "\n", 2)[0]) | ||
| return fmt.Sprintf(" %-22s %s", c, strings.SplitN(d, "\n", 2)[0]) | ||
|
||
| } | ||
|
|
||
| var commands []string | ||
|
|
@@ -284,7 +284,16 @@ func usage(commandLine bool) string { | |
| radioOptions[vr.group] = append(radioOptions[vr.group], name) | ||
| continue | ||
| } | ||
| variables = append(variables, fmtHelp(prefix+name, vr.help)) | ||
| option := prefix + name | ||
| if vr.kind == intKind { | ||
nolanmar511 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wyk9787 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| option += " = <n>" | ||
| } else if vr.kind == floatKind { | ||
| option += " = <f>" | ||
| } else if name == "sample_index" { | ||
| option += " = <x>" | ||
| } | ||
|
|
||
| variables = append(variables, fmtHelp(option, vr.help)) | ||
| } | ||
| sort.Strings(variables) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,11 @@ func interactive(p *profile.Profile, o *plugin.Options) error { | |
| value = strings.TrimSpace(value) | ||
| } | ||
| if v := pprofVariables[name]; v != nil { | ||
| // All non-bool options require inputs | ||
| if v.kind != boolKind && value == "" { | ||
| o.UI.PrintErr(fmt.Errorf("please input a value, e.g. option = value")) | ||
nolanmar511 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| continue | ||
| } | ||
| if name == "sample_index" { | ||
| // Error check sample_index=xxx to ensure xxx is a valid sample type. | ||
| index, err := p.SampleIndexByName(value) | ||
|
|
@@ -267,6 +272,9 @@ func parseCommandLine(input []string) ([]string, variables, error) { | |
| } | ||
| } | ||
| if c == nil { | ||
| if v := pprofVariables[name]; v != nil { | ||
| return nil, nil, fmt.Errorf("do you mean: \"%v=%v\"?", name, args[0]) | ||
|
||
| } | ||
| return nil, nil, fmt.Errorf("unrecognized command: %q", name) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.