Skip to content

Commit c0dde45

Browse files
committed
Add version printing and adjust kong config slightly
1 parent eaed01e commit c0dde45

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/main.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"github.com/alecthomas/kong"
56
"github.com/hauke96/sigolo"
67
"os"
@@ -19,15 +20,17 @@ import (
1920
"wiki2book/util"
2021
)
2122

23+
const VERSION = "v0.1.0"
2224
const RFC1123Millis = "Mon, 02 Jan 2006 15:04:05.999 MST"
2325

2426
var cli struct {
25-
Logging string `help:"Logging verbosity. Possible values: debug, trace" short:"l"`
26-
DiagnosticsProfiling bool `help:"Enable profiling and write results to ./profiling.prof."`
27-
DiagnosticsTrace bool `help:"Enable tracing to analyse memory usage and write results to ./trace.out."`
28-
ForceRegenerateHtml bool `help:"Forces wiki2book to recreate HTML files even if they exists from a previous run." short:"r"`
29-
SvgSizeToViewbox bool `help:"Sets the 'width' and 'height' property of an SimpleSvgAttributes image to its viewbox width and height. This might fix wrong SVG sizes on some eBook-readers."`
30-
Config string `help:"The path to the overall application config. If not specified, default values are used." type:"existingfile" short:"c" placeholder:"<file>"`
27+
Logging string `help:"Logging verbosity. Possible values: debug, trace" short:"l"`
28+
DiagnosticsProfiling bool `help:"Enable profiling and write results to ./profiling.prof."`
29+
DiagnosticsTrace bool `help:"Enable tracing to analyse memory usage and write results to ./trace.out."`
30+
ForceRegenerateHtml bool `help:"Forces wiki2book to recreate HTML files even if they exists from a previous run." short:"r"`
31+
SvgSizeToViewbox bool `help:"Sets the 'width' and 'height' property of an SimpleSvgAttributes image to its viewbox width and height. This might fix wrong SVG sizes on some eBook-readers."`
32+
Config string `help:"The path to the overall application config. If not specified, default values are used." type:"existingfile" short:"c" placeholder:"<file>"`
33+
Version VersionFlag `help:"Print version information and quit" name:"version" short:"v"`
3134
Standalone struct {
3235
File string `help:"A mediawiki file tha should be rendered to an eBook." arg:""`
3336
OutputFile string `help:"The path to the EPUB-file." short:"o" default:"ebook.epub" placeholder:"<file>"`
@@ -53,8 +56,25 @@ var cli struct {
5356
} `cmd:"" help:"Renders a single article into an eBook."`
5457
}
5558

59+
type VersionFlag string
60+
61+
func (v VersionFlag) Decode(ctx *kong.DecodeContext) error { return nil }
62+
func (v VersionFlag) IsBool() bool { return true }
63+
func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error {
64+
fmt.Println(vars["version"])
65+
app.Exit(0)
66+
return nil
67+
}
68+
5669
func main() {
57-
ctx := kong.Parse(&cli)
70+
ctx := kong.Parse(
71+
&cli,
72+
kong.Name("wiki2book"),
73+
kong.Description("A CLI tool to turn one or multiple Wikipedia articles into a good-looking eBook."),
74+
kong.Vars{
75+
"version": VERSION,
76+
},
77+
)
5878

5979
if strings.ToLower(cli.Logging) == "debug" {
6080
sigolo.LogLevel = sigolo.LOG_DEBUG

0 commit comments

Comments
 (0)