소스 검색

Add comments for options processing

Raul Silvera 8 년 전
부모
커밋
93af41bcc6
2개의 변경된 파일7개의 추가작업 그리고 1개의 파일을 삭제
  1. 1
    0
      internal/driver/commands.go
  2. 6
    1
      internal/driver/interactive.go

+ 1
- 0
internal/driver/commands.go 파일 보기

@@ -536,6 +536,7 @@ func (vars variables) set(name, value string) error {
536 536
 	case floatKind:
537 537
 		_, err = strconv.ParseFloat(value, 64)
538 538
 	case stringKind:
539
+		// Remove quotes, particularly useful for empty values.
539 540
 		if len(value) > 1 && strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) {
540 541
 			value = value[1 : len(value)-1]
541 542
 		}

+ 6
- 1
internal/driver/interactive.go 파일 보기

@@ -66,6 +66,7 @@ func interactive(p *profile.Profile, o *plugin.Options) error {
66 66
 				}
67 67
 				if v := pprofVariables[name]; v != nil {
68 68
 					if name == "sample_index" {
69
+						// Error check sample_index=xxx to ensure xxx is a valid sample type.
69 70
 						index, err := locateSampleIndex(p, value)
70 71
 						if err != nil {
71 72
 							o.UI.PrintErr(err)
@@ -78,6 +79,7 @@ func interactive(p *profile.Profile, o *plugin.Options) error {
78 79
 					}
79 80
 					continue
80 81
 				}
82
+				// Allow group=variable syntax by converting into variable="".
81 83
 				if v := pprofVariables[value]; v != nil && v.group == name {
82 84
 					if err := pprofVariables.set(value, ""); err != nil {
83 85
 						o.UI.PrintErr(err)
@@ -183,14 +185,17 @@ func printCurrentOptions(p *profile.Profile, ui plugin.UI) {
183 185
 		case n == "sample_index":
184 186
 			st := sampleTypes(p)
185 187
 			if v == "" {
188
+				// Apply default (last sample index).
186 189
 				v = st[len(st)-1]
187 190
 			}
191
+			// Add comments for all sample types in profile.
188 192
 			comment = "[" + strings.Join(st, " | ") + "]"
189 193
 		case n == "source_path":
190 194
 			continue
191 195
 		case n == "nodecount" && v == "-1":
192 196
 			comment = "default"
193 197
 		case v == "":
198
+			// Add quotes for empty values.
194 199
 			v = `""`
195 200
 		}
196 201
 		if comment != "" {
@@ -204,7 +209,7 @@ func printCurrentOptions(p *profile.Profile, ui plugin.UI) {
204 209
 		args = append(args, fmt.Sprintf("  %-25s = %-20s %s", g, vars.set, comment))
205 210
 	}
206 211
 	sort.Strings(args)
207
-	ui.PrintErr(strings.Join(args, "\n"))
212
+	ui.Print(strings.Join(args, "\n"))
208 213
 }
209 214
 
210 215
 // parseCommandLine parses a command and returns the pprof command to