-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle.go
30 lines (24 loc) · 1 KB
/
single.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"github.com/alecthomas/kong"
"gitlab.com/tozd/go/errors"
"gitlab.com/tozd/go/zerolog"
"gitlab.com/tozd/go/cli"
)
const DefaultMessage = "Hello world!"
//nolint:lll
type App struct {
zerolog.LoggingConfig `yaml:",inline"`
Version kong.VersionFlag ` help:"Show program's version and exit." short:"V" yaml:"-"`
Config cli.ConfigFlag ` help:"Load configuration from a JSON or YAML file." name:"config" placeholder:"PATH" short:"c" yaml:"-"`
Message string `arg:"" default:"${defaultMessage}" help:"Message to output. Default: ${defaultMessage}." optional:"" placeholder:"STRING" yaml:"message"`
}
func main() {
var app App
cli.Run(&app, kong.Vars{
"defaultMessage": DefaultMessage,
}, func(ctx *kong.Context) errors.E {
app.Logger.Info().Str("program", ctx.Model.Name).Msg(app.Message)
return nil
})
}