Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usage string and document stdin/stdout behavior. #51

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add usage string and document stdin/stdout behavior.
Expose public method that can be called externally.
  • Loading branch information
nanaze committed Nov 14, 2024
commit 2a37c919586b69dc0da030d3719cb443b91537b6
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main
import (
"fmt"
"os"
"path"
"time"

"github.com/google/keep-sorted/cmd"
Expand All @@ -27,6 +28,12 @@ import (
flag "github.com/spf13/pflag"
)

func PrintUsage() {
nanaze marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintf(os.Stderr, "Usage: %s [flags] file1 [file2 ...]\n\n", path.Base(os.Args[0]))
fmt.Fprint(os.Stderr, "Note that '-' can be used to read from stdin, "+
"in which case the output is written to stdout.\n\n")
}

func main() {
c := &cmd.Config{}
c.FromFlags(nil)
Expand All @@ -36,6 +43,13 @@ func main() {
if err := flag.CommandLine.MarkHidden("omit-timestamps"); err != nil {
panic(err)
}

flag.Usage = func() {
PrintUsage()
fmt.Fprintln(os.Stderr, "Flags:")
nanaze marked this conversation as resolved.
Show resolved Hide resolved
flag.PrintDefaults()
}

flag.Parse()

out := os.Stderr
Expand Down
Loading