|
1 | 1 | package main |
2 | 2 |
|
3 | | -import _ "embed" |
| 3 | +import ( |
| 4 | + _ "embed" |
| 5 | + "fmt" |
| 6 | + "strings" |
| 7 | +) |
4 | 8 |
|
5 | 9 | //go:embed templates/detailed.html |
6 | 10 | var detailedHTMLTemplateStr string |
7 | 11 |
|
8 | 12 | //go:embed templates/aggregate.html |
9 | 13 | var aggregateHTMLTemplate string |
10 | 14 |
|
11 | | -const helpText = `Usage: |
12 | | - wrap /path/to/binary |
13 | | - Wrap the given ELF binary with the Pin coverage wrapper. |
| 15 | +const wrapHelpText = `Usage: funkoverage wrap /path/to/binary |
| 16 | +Wrap the given ELF binary with the Pin coverage wrapper.` |
14 | 17 |
|
15 | | - unwrap /path/to/binary |
16 | | - Restore the original binary previously wrapped. |
| 18 | +const unwrapHelpText = `Usage: funkoverage unwrap /path/to/binary |
| 19 | +Restore the original binary previously wrapped.` |
17 | 20 |
|
18 | | - report <inputdir|log1.txt,log2.txt> <outputdir> [--formats <formats>] |
19 | | - Generate coverage reports from log files. |
20 | | - <inputdir> Directory containing .log files (all will be used) |
21 | | - log1.txt,log2.txt Comma-separated list of log files |
22 | | - <outputdir> Output directory for reports (mandatory) |
23 | | - --formats Comma-separated list: html,xml,txt (default: html,txt,xml) |
| 21 | +const reportHelpText = `Usage: funkoverage report <inputdir|log1.txt,log2.txt> <outputdir> [--formats <formats>] |
24 | 22 |
|
| 23 | +Generate coverage reports from log files. |
| 24 | + <inputdir> Directory containing .log files (all will be used) |
| 25 | + log1.txt,log2.txt Comma-separated list of log files |
| 26 | + <outputdir> Output directory for reports (mandatory) |
| 27 | + --formats Comma-separated list: html,xml,txt (default: html,txt,xml) |
| 28 | +` |
| 29 | + |
| 30 | +var helpText string |
| 31 | + |
| 32 | +func init() { |
| 33 | + // We use fmt.Sprintf to build the main help text from the subcommand help texts |
| 34 | + // to avoid duplication. The subcommand help texts are modified slightly for |
| 35 | + // proper formatting in the main help view. |
| 36 | + helpText = fmt.Sprintf(`Usage: |
| 37 | + %s |
| 38 | + %s |
| 39 | + %s |
25 | 40 | help |
26 | 41 | Show this help message. |
27 | | -
|
28 | 42 | version |
29 | 43 | Show program version. |
30 | 44 |
|
31 | 45 | Environment variables: |
32 | 46 | PIN_ROOT Path to Intel Pin root directory (default: autodetect or required) |
33 | 47 | PIN_TOOL_SEARCH_DIR Directory to search for FuncTracer.so (default: /usr/lib64/coverage-tools) |
34 | 48 | LOG_DIR Directory for coverage logs (default: /var/coverage/data) |
35 | | - SAFE_BIN_DIR Directory to store original binaries (default: /var/coverage/bin)` |
| 49 | + SAFE_BIN_DIR Directory to store original binaries (default: /var/coverage/bin) |
| 50 | +`, |
| 51 | + indent(strings.TrimPrefix(wrapHelpText, "Usage: funkoverage "), " "), |
| 52 | + indent(strings.TrimPrefix(unwrapHelpText, "Usage: funkoverage "), " "), |
| 53 | + indent(strings.TrimPrefix(reportHelpText, "Usage: funkoverage "), " ")) |
| 54 | +} |
| 55 | + |
| 56 | +// indent adds indentation to each line of a string. |
| 57 | +func indent(text, indentation string) string { |
| 58 | + return indentation + strings.ReplaceAll(strings.TrimSpace(text), "\n", "\n"+indentation) |
| 59 | +} |
0 commit comments