Skip to content

Commit b69474b

Browse files
committed
fix: store usage in text file
Fixes the mixed tab and space identation introduced by code formatting.
1 parent b6a5722 commit b69474b

File tree

4 files changed

+56
-54
lines changed

4 files changed

+56
-54
lines changed

cmd/chart/testdata/script/help.txtar

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ USAGE:
99
chart [OPTIONS]
1010

1111
OPTIONS:
12-
-p, --precision INT Precision for values (default: 80)
12+
-p, --precision INT Precision for values (default: 80)
1313
-c, --count Count line occurrences
1414
-d, --desc Sort chart in descending order
1515
-i, --in FILE Read data from file instead of stdin
1616
-l, --length INT Set maximum chart length (default: 20)
1717
-L, --label-length INT Set maximum label length (default: 2)
1818
-m, --mermaid Create Mermaid XYChart
19-
-C, --chartjs Create Chart.js configuration
19+
-C, --chartjs Create Chart.js configuration
2020
-o, --out FILE Write to file instead of stdout (overwrites contents)
2121
-s, --sort SORT Sort chart; see SORT OPTIONS below
2222
-t, --tick CHAR Use specified character for drawing bars
23-
-T, --title TITLE Chart title (Mermaid).
24-
-v, --version Display version information and exit
23+
-T, --title TITLE Chart title (Mermaid).
24+
-v, --version Display version information and exit
2525

2626
SORT OPTIONS:
27-
none: Keep order of insertion (default)
27+
none: Keep order of insertion (default)
2828
label: Alphabetically sort bars by label
2929
labelnum: Numerically sort bars by label
3030
value: Numerically sort bars by value
@@ -39,8 +39,8 @@ EXAMPLES:
3939
# Sort chart by value in descending order:
4040
$ cat data.txt | chart --count --sort value --desc
4141

42-
# Generate a Mermaid XYChart:
43-
$ cat data.txt | chart --mermaid
42+
# Generate a Mermaid XYChart:
43+
$ cat data.txt | chart --mermaid
4444

45-
# Generate a Chart.js configuration:
46-
$ cat data.txt | chart --chartjs
45+
# Generate a Chart.js configuration:
46+
$ cat data.txt | chart --chartjs

internal/cli/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
var buildInfo *debug.BuildInfo
1111

12-
var version = "0.1.0"
12+
var version = "0.1.1"
1313

1414
// Version returns the current version of the CLI application.
1515
func Version() string {

internal/cli/flags.go

+4-44
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
_ "embed"
45
"errors"
56
"flag"
67
"fmt"
@@ -19,49 +20,8 @@ const (
1920
defaultSort = "none"
2021
)
2122

22-
const Usage = `DESCRIPTION
23-
Render bar charts from file contents and command output in various formats.
24-
25-
USAGE:
26-
chart [OPTIONS]
27-
28-
OPTIONS:
29-
-p, --precision INT Precision for values (default: %d)
30-
-c, --count Count line occurrences
31-
-d, --desc Sort chart in descending order
32-
-i, --in FILE Read data from file instead of stdin
33-
-l, --length INT Set maximum chart length (default: %d)
34-
-L, --label-length INT Set maximum label length (default: %d)
35-
-m, --mermaid Create Mermaid XYChart
36-
-C, --chartjs Create Chart.js configuration
37-
-o, --out FILE Write to file instead of stdout (overwrites contents)
38-
-s, --sort SORT Sort chart; see SORT OPTIONS below
39-
-t, --tick CHAR Use specified character for drawing bars
40-
-T, --title TITLE Chart title (Mermaid).
41-
-v, --version Display version information and exit
42-
43-
SORT OPTIONS:
44-
none: Keep order of insertion (default)
45-
label: Alphabetically sort bars by label
46-
labelnum: Numerically sort bars by label
47-
value: Numerically sort bars by value
48-
49-
EXAMPLES:
50-
# Chart 'uniq -c' command output:
51-
$ cat data.txt | sort | uniq -c | chart
52-
53-
# Chart contents of file by counting lines:
54-
$ chart --in data.txt --count
55-
56-
# Sort chart by value in descending order:
57-
$ cat data.txt | chart --count --sort value --desc
58-
59-
# Generate a Mermaid XYChart:
60-
$ cat data.txt | chart --mermaid
61-
62-
# Generate a Chart.js configuration:
63-
$ cat data.txt | chart --chartjs
64-
`
23+
//go:embed usage.txt
24+
var usage string
6525

6626
var sortOptMap = map[string]chart.SortOption{
6727
"none": chart.SortNone,
@@ -186,7 +146,7 @@ func printUsage(err error) {
186146
fmt.Fprintf(os.Stderr, "Error: %v\n\n", err)
187147
}
188148

189-
fmt.Fprintf(os.Stderr, Usage, defaultMaxLength, defaultMaxLabelLength, defaultPrecision)
149+
fmt.Fprintf(os.Stderr, usage, defaultMaxLength, defaultMaxLabelLength, defaultPrecision)
190150
}
191151

192152
func boolFlag(flagset *flag.FlagSet, p *bool, name, short string, value bool, usage string) { //nolint:revive // acceptable arg count.

internal/cli/usage.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
DESCRIPTION
2+
Render bar charts from file contents and command output in various formats.
3+
4+
USAGE:
5+
chart [OPTIONS]
6+
7+
OPTIONS:
8+
-p, --precision INT Precision for values (default: %d)
9+
-c, --count Count line occurrences
10+
-d, --desc Sort chart in descending order
11+
-i, --in FILE Read data from file instead of stdin
12+
-l, --length INT Set maximum chart length (default: %d)
13+
-L, --label-length INT Set maximum label length (default: %d)
14+
-m, --mermaid Create Mermaid XYChart
15+
-C, --chartjs Create Chart.js configuration
16+
-o, --out FILE Write to file instead of stdout (overwrites contents)
17+
-s, --sort SORT Sort chart; see SORT OPTIONS below
18+
-t, --tick CHAR Use specified character for drawing bars
19+
-T, --title TITLE Chart title (Mermaid).
20+
-v, --version Display version information and exit
21+
22+
SORT OPTIONS:
23+
none: Keep order of insertion (default)
24+
label: Alphabetically sort bars by label
25+
labelnum: Numerically sort bars by label
26+
value: Numerically sort bars by value
27+
28+
EXAMPLES:
29+
# Chart 'uniq -c' command output:
30+
$ cat data.txt | sort | uniq -c | chart
31+
32+
# Chart contents of file by counting lines:
33+
$ chart --in data.txt --count
34+
35+
# Sort chart by value in descending order:
36+
$ cat data.txt | chart --count --sort value --desc
37+
38+
# Generate a Mermaid XYChart:
39+
$ cat data.txt | chart --mermaid
40+
41+
# Generate a Chart.js configuration:
42+
$ cat data.txt | chart --chartjs

0 commit comments

Comments
 (0)