Skip to content

Commit 18fa83d

Browse files
committed
README files for everything
1 parent 84b6353 commit 18fa83d

File tree

19 files changed

+340
-227
lines changed

19 files changed

+340
-227
lines changed

cmd/asciify/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# asciify
2+
3+
Convert non-ASCII characters to ASCII

cmd/asciify/asciify.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package main
22

33
import (
4+
_ "embed"
45
"fmt"
56
"os"
67

78
anyascii "github.com/anyascii/go"
9+
"github.com/spf13/pflag"
810
"golang.org/x/text/encoding/charmap"
911
)
1012

@@ -15,8 +17,27 @@ var (
1517
VERSION = "internal"
1618
)
1719

20+
//go:embed README.md
21+
var helpText string
22+
1823
func main() {
1924

25+
var help = pflag.BoolP("help", "h", false, "Show help message")
26+
var version = pflag.Bool("version", false, "Print version information")
27+
28+
pflag.Parse()
29+
30+
if *version {
31+
fmt.Fprintf(os.Stdout, "asciify version %s (built by %s on %s, commit %s)\n", VERSION, BUILDER, LASTMOD, COMMIT)
32+
return
33+
}
34+
35+
if *help {
36+
fmt.Printf("Usage: asciify [options] [file...]\n\n")
37+
fmt.Printf("%s\n", helpText)
38+
return
39+
}
40+
2041
input, err := os.ReadFile("/dev/stdin")
2142
if err != nil {
2243
fmt.Fprintln(os.Stderr, "Error reading stdin:", err)

cmd/asciitable/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# asciitable
2+
3+
Print a table of the ASCII character set

cmd/asciitable/asciitable.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package main
22

33
import (
4+
_ "embed"
45
"fmt"
56
"os"
67

78
"github.com/olekukonko/tablewriter"
89
"github.com/olekukonko/tablewriter/renderer"
910
"github.com/olekukonko/tablewriter/tw"
11+
"github.com/spf13/pflag"
1012
"golang.org/x/text/encoding/charmap"
1113
)
1214

@@ -17,6 +19,9 @@ var (
1719
VERSION = "internal"
1820
)
1921

22+
//go:embed README.md
23+
var helpText string
24+
2025
var asciiMap = map[int]string{
2126
0x00: "NUL", 0x01: "SOH", 0x02: "STX", 0x03: "ETX",
2227
0x04: "EOT", 0x05: "ENQ", 0x06: "ACK", 0x07: "BEL",
@@ -30,6 +35,22 @@ var asciiMap = map[int]string{
3035

3136
func main() {
3237

38+
var help = pflag.BoolP("help", "h", false, "Show help message")
39+
var version = pflag.Bool("version", false, "Print version information")
40+
41+
pflag.Parse()
42+
43+
if *version {
44+
fmt.Fprintf(os.Stdout, "asciitable version %s (built by %s on %s, commit %s)\n", VERSION, BUILDER, LASTMOD, COMMIT)
45+
return
46+
}
47+
48+
if *help {
49+
fmt.Printf("Usage: asciitable\n\n")
50+
fmt.Printf("%s\n", helpText)
51+
return
52+
}
53+
3354
// LATER: option to output markdown or pure ASCII (i.e. not using box-drawing characters)
3455
table := tablewriter.NewTable(os.Stdout,
3556
tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{

cmd/bytecount/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# bytecount
2+
3+
Count each byte value in a file

cmd/bytecount/bytecount.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package main
22

33
import (
44
"bufio"
5+
_ "embed"
56
"fmt"
67
"io"
78
"os"
89

10+
"github.com/mattn/go-isatty"
911
"github.com/olekukonko/tablewriter"
1012
"github.com/olekukonko/tablewriter/renderer"
1113
"github.com/olekukonko/tablewriter/tw"
@@ -21,6 +23,9 @@ var (
2123
VERSION = "internal"
2224
)
2325

26+
//go:embed README.md
27+
var helpText string
28+
2429
func outputPretty(out io.Writer, counts map[byte]int) {
2530

2631
// LATER: use https://github.com/jeandeaual/go-locale to determine locale
@@ -103,17 +108,20 @@ func main() {
103108
}
104109

105110
if *help {
106-
// LATER: print man page
107111
fmt.Printf("Usage: bytecount [options] [file...]\n\n")
108112
fmt.Printf("Options:\n")
109113
pflag.PrintDefaults()
114+
fmt.Printf("%s\n", helpText)
110115
return
111116
}
112117

113118
args := pflag.Args()
114119
if len(args) == 0 {
115-
fmt.Printf("Usage: bytecount [options] file ...\n\n")
116-
return
120+
if !isatty.IsTerminal(os.Stdin.Fd()) {
121+
fmt.Printf("No input files specified and no data piped to stdin.\n\n")
122+
os.Exit(1)
123+
}
124+
args = append(args, "-")
117125
}
118126

119127
for _, arg := range args {

cmd/certinfo/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# certinfo
2+
3+
Prints info about X.509 (SSL/TLS) certificates
4+
5+
6+
## Examples
7+
8+
9+
```
10+
certinfo https://resolve.rs/
11+
```
12+
13+
```
14+
certinfo mycert.pem
15+
```

cmd/certinfo/certinfo.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import (
44
"bytes"
55
"crypto/tls"
66
"crypto/x509"
7+
_ "embed"
78
"encoding/pem"
89
"fmt"
910
"log"
1011
"os"
1112
"strings"
13+
14+
"github.com/spf13/pflag"
1215
)
1316

1417
var (
@@ -18,13 +21,8 @@ var (
1821
VERSION = "internal"
1922
)
2023

21-
func usage() {
22-
fmt.Fprintf(os.Stderr, "Usage: certinfo url|file\n")
23-
fmt.Fprintf(os.Stderr, "Examples:\n")
24-
fmt.Fprintf(os.Stderr, " certinfo https://google.com\n")
25-
fmt.Fprintf(os.Stderr, " certinfo mycert.pem\n")
26-
os.Exit(1)
27-
}
24+
//go:embed README.md
25+
var helpText string
2826

2927
func getHttpsCerts(url string) ([]*x509.Certificate, error) {
3028

@@ -51,13 +49,32 @@ func getHttpsCerts(url string) ([]*x509.Certificate, error) {
5149

5250
func main() {
5351

54-
if len(os.Args) < 2 {
55-
usage()
52+
var help = pflag.BoolP("help", "h", false, "Show help message")
53+
var version = pflag.Bool("version", false, "Print version information")
54+
55+
pflag.Parse()
56+
57+
if *version {
58+
fmt.Fprintf(os.Stdout, "certinfo version %s (built by %s on %s, commit %s)\n", VERSION, BUILDER, LASTMOD, COMMIT)
59+
return
60+
}
61+
62+
if *help {
63+
fmt.Printf("Usage: certinfo [options] file ...\n\n")
64+
fmt.Printf("Options:\n")
65+
pflag.PrintDefaults()
66+
fmt.Printf("%s\n", helpText)
67+
return
68+
}
69+
70+
if len(pflag.Args()) < 1 {
71+
fmt.Fprintf(os.Stderr, "Usage: certinfo [options] file|url ...\n")
72+
os.Exit(1)
5673
}
5774

5875
var certs []*x509.Certificate
5976

60-
for _, arg := range os.Args[1:] {
77+
for _, arg := range pflag.Args() {
6178
if strings.HasPrefix(arg, "https://") {
6279
httpsCerts, httpsErr := getHttpsCerts(arg)
6380
if httpsErr != nil {

cmd/ghash/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ghash
2+
3+
Print file hashes with all the algorithms in the Go standard library.

cmd/ghash/ghash.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
_ "crypto/sha256"
99
_ "crypto/sha3"
1010
_ "crypto/sha512"
11+
_ "embed"
1112
"hash"
1213
"io"
1314
"regexp"
@@ -31,6 +32,9 @@ var (
3132
VERSION = "internal"
3233
)
3334

35+
//go:embed README.md
36+
var helpText string
37+
3438
// struct with name and hash
3539
type Hasher struct {
3640
name string
@@ -88,8 +92,24 @@ func main() {
8892
pflag.BoolVar(&list, "list", false, "List available hash algorithms")
8993
//LATER: output format
9094

95+
var help = pflag.BoolP("help", "h", false, "Show help message")
96+
var version = pflag.Bool("version", false, "Print version information")
97+
9198
pflag.Parse()
9299

100+
if *version {
101+
fmt.Fprintf(os.Stdout, "ghash version %s (built by %s on %s, commit %s)\n", VERSION, BUILDER, LASTMOD, COMMIT)
102+
return
103+
}
104+
105+
if *help {
106+
fmt.Printf("Usage: ghash [options] file ...\n\n")
107+
fmt.Printf("Options:\n")
108+
pflag.PrintDefaults()
109+
fmt.Printf("%s\n", helpText)
110+
return
111+
}
112+
93113
if list {
94114
for i := crypto.MD4; i <= crypto.BLAKE2b_512; i++ {
95115
hashName := nonAlphaNumeric.ReplaceAllString(strings.ToLower(i.String()), "")

0 commit comments

Comments
 (0)