go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

commit 6e91d0e9e45341b48781fb3ff4cccecee6770af0
parent ed19491a4e06bcb31bf2e877975727d017f554ed
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Thu, 19 Oct 2023 11:41:15 +0800

cmd: show help at command level

Be a bit more useful at the high level, telling the user what commands
are available.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>

Diffstat:
Mcmd/main.go | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -4,10 +4,12 @@ import ( "flag" "fmt" "image" + "image/png" "os" + "strings" _ "image/jpeg" - "image/png" + _ "image/png" "git.sr.ht/~jackmordaunt/go-libwebp/webp" @@ -16,10 +18,15 @@ import ( func main() { if err := run(os.Args[1:]); err != nil { fmt.Printf("error: %v\n", err) + os.Exit(1) } } func run(args []string) error { + if len(args) == 0 || isHelp(args[0]) { + fmt.Printf("Usage: specify command [encode, decode]\n") + return nil + } if len(args) < 1 { return fmt.Errorf("not enough arguments") } @@ -33,6 +40,10 @@ func run(args []string) error { } } +func isHelp(s string) bool { + return strings.HasPrefix(s, "-h") +} + func encodeWebp(args []string) error { var ( quality float64 @@ -71,9 +82,7 @@ func encodeWebp(args []string) error { } func decodeWebp(args []string) error { - var ( - output string - ) + var output string cli := flag.NewFlagSet("decode", flag.ExitOnError) cli.StringVar(&output, "o", "out.png", "path to output file") if err := cli.Parse(args); err != nil {