Skip to content

Commit

Permalink
Add --version option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronsor committed Jan 3, 2023
1 parent 7c97d34 commit 71fb1b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
26 changes: 21 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var hasError = false

var (
doHelp = false
doVersion = false
doIdentify = false
doConvert = false
doListFormats = false
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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?")
Expand All @@ -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
Expand Down

0 comments on commit 71fb1b7

Please sign in to comment.