From 71fb1b78a72ed55bb40e21847a887a19ada968e7 Mon Sep 17 00:00:00 2001 From: Ronsor Date: Mon, 2 Jan 2023 18:52:26 -0700 Subject: [PATCH] Add --version option --- README.md | 2 +- main.go | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ff5f743..2b48f72 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ D-- WEBP ## License and Copyright Notice -Copyright © 2022-2023 Ronsor Labs. +Copyright © 2022-2023 Ronsor Labs This software is provided to you under the terms of the MIT license. See the included `LICENSE` file for more information. diff --git a/main.go b/main.go index 324adea..c0028d7 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ var hasError = false var ( doHelp = false + doVersion = false doIdentify = false doConvert = false doListFormats = false @@ -41,6 +42,7 @@ type FilterArgs struct { func init() { getopt.FlagLong(&doHelp, "help", 'h', "Show this help information") + getopt.FlagLong(&doVersion, "version", 'v', "Show version information") getopt.FlagLong(&doIdentify, "identify", 0, "Print information about the image").SetGroup("action") getopt.FlagLong(&doConvert, "convert", 0, "Convert or process image (default)").SetGroup("action") getopt.FlagLong(&doListFormats, "list-formats", 0, "List supported image formats").SetGroup("action") @@ -118,6 +120,15 @@ func actionConvert(wand *henshin.Wand, logPrefix string, maxArg int, args []stri } } +func actionVersion() { + fmt.Printf("Majokko %s (C) 2022-2023 Ronsor Labs. Licensed under the MIT license.\n", VERSION) + fmt.Printf("Supported formats:") + for _, c := range henshin.Codecs() { + fmt.Printf(" %s", c.Name()) + } + fmt.Printf("\nFor more information, use the --list-formats option.\n") +} + func main() { getopt.Parse() args := getopt.Args() @@ -127,13 +138,11 @@ func main() { return } - if !doConvert { - doConvert = !doIdentify + if doVersion { + actionVersion() + if !doListFormats { return } } - maxArg := len(args) - if doConvert { maxArg = maxArg - 1 } - if doListFormats { fmt.Println("+---- Can decode?") fmt.Println("|+--- Can encode?") @@ -153,6 +162,13 @@ func main() { return } + if !doConvert { + doConvert = !doIdentify + } + + maxArg := len(args) + if doConvert { maxArg = maxArg - 1 } + var wg sync.WaitGroup n := 0