Skip to content

Commit

Permalink
fix: store usage in text file
Browse files Browse the repository at this point in the history
Fixes the mixed tab and space identation introduced by code formatting.
  • Loading branch information
michenriksen committed Jul 7, 2024
1 parent b6a5722 commit b69474b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 54 deletions.
18 changes: 9 additions & 9 deletions cmd/chart/testdata/script/help.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ USAGE:
chart [OPTIONS]

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

SORT OPTIONS:
none: Keep order of insertion (default)
none: Keep order of insertion (default)
label: Alphabetically sort bars by label
labelnum: Numerically sort bars by label
value: Numerically sort bars by value
Expand All @@ -39,8 +39,8 @@ EXAMPLES:
# Sort chart by value in descending order:
$ cat data.txt | chart --count --sort value --desc

# Generate a Mermaid XYChart:
$ cat data.txt | chart --mermaid
# Generate a Mermaid XYChart:
$ cat data.txt | chart --mermaid

# Generate a Chart.js configuration:
$ cat data.txt | chart --chartjs
# Generate a Chart.js configuration:
$ cat data.txt | chart --chartjs
2 changes: 1 addition & 1 deletion internal/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var buildInfo *debug.BuildInfo

var version = "0.1.0"
var version = "0.1.1"

// Version returns the current version of the CLI application.
func Version() string {
Expand Down
48 changes: 4 additions & 44 deletions internal/cli/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
_ "embed"
"errors"
"flag"
"fmt"
Expand All @@ -19,49 +20,8 @@ const (
defaultSort = "none"
)

const Usage = `DESCRIPTION
Render bar charts from file contents and command output in various formats.
USAGE:
chart [OPTIONS]
OPTIONS:
-p, --precision INT Precision for values (default: %d)
-c, --count Count line occurrences
-d, --desc Sort chart in descending order
-i, --in FILE Read data from file instead of stdin
-l, --length INT Set maximum chart length (default: %d)
-L, --label-length INT Set maximum label length (default: %d)
-m, --mermaid Create Mermaid XYChart
-C, --chartjs Create Chart.js configuration
-o, --out FILE Write to file instead of stdout (overwrites contents)
-s, --sort SORT Sort chart; see SORT OPTIONS below
-t, --tick CHAR Use specified character for drawing bars
-T, --title TITLE Chart title (Mermaid).
-v, --version Display version information and exit
SORT OPTIONS:
none: Keep order of insertion (default)
label: Alphabetically sort bars by label
labelnum: Numerically sort bars by label
value: Numerically sort bars by value
EXAMPLES:
# Chart 'uniq -c' command output:
$ cat data.txt | sort | uniq -c | chart
# Chart contents of file by counting lines:
$ chart --in data.txt --count
# Sort chart by value in descending order:
$ cat data.txt | chart --count --sort value --desc
# Generate a Mermaid XYChart:
$ cat data.txt | chart --mermaid
# Generate a Chart.js configuration:
$ cat data.txt | chart --chartjs
`
//go:embed usage.txt
var usage string

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

fmt.Fprintf(os.Stderr, Usage, defaultMaxLength, defaultMaxLabelLength, defaultPrecision)
fmt.Fprintf(os.Stderr, usage, defaultMaxLength, defaultMaxLabelLength, defaultPrecision)
}

func boolFlag(flagset *flag.FlagSet, p *bool, name, short string, value bool, usage string) { //nolint:revive // acceptable arg count.
Expand Down
42 changes: 42 additions & 0 deletions internal/cli/usage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
DESCRIPTION
Render bar charts from file contents and command output in various formats.

USAGE:
chart [OPTIONS]

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

SORT OPTIONS:
none: Keep order of insertion (default)
label: Alphabetically sort bars by label
labelnum: Numerically sort bars by label
value: Numerically sort bars by value

EXAMPLES:
# Chart 'uniq -c' command output:
$ cat data.txt | sort | uniq -c | chart

# Chart contents of file by counting lines:
$ chart --in data.txt --count

# Sort chart by value in descending order:
$ cat data.txt | chart --count --sort value --desc

# Generate a Mermaid XYChart:
$ cat data.txt | chart --mermaid

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

0 comments on commit b69474b

Please sign in to comment.