-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (34 loc) · 890 Bytes
/
main.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
31
32
33
34
35
36
37
38
39
40
41
// cspell:ignore kongplete
package main
import (
"os"
"reflect"
"regexp"
"github.com/alecthomas/kong"
)
var cmd struct {
Clean clean `cmd:"" help:"Remove cache."`
Run run `cmd:"" help:"Execute a command."`
}
type regexpMapper bool
func (m regexpMapper) Decode(ctx *kong.DecodeContext, target reflect.Value) error {
var regexString string
if err := ctx.Scan.PopValueInto("regex", ®exString); err != nil {
return err
}
r, err := regexp.CompilePOSIX(regexString)
if err != nil {
return err
}
target.Set(reflect.ValueOf(r))
return nil
}
func main() {
parser := kong.Must(&cmd,
kong.Description("Automatically clone and execute commands across multiple GitHub repositories."),
kong.TypeMapper(reflect.TypeOf(®exp.Regexp{}), regexpMapper(false)))
ctx, err := parser.Parse(os.Args[1:])
parser.FatalIfErrorf(err)
err = ctx.Run()
ctx.FatalIfErrorf(err)
}