-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (59 loc) · 2.15 KB
/
Copy pathmain.go
File metadata and controls
75 lines (59 loc) · 2.15 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/debug"
"github.com/wendigo/go-bind-plugin/cli"
)
// set by goreleaser via ldflags
var (
version = ""
commit = ""
date = ""
)
func versionString() string {
v := version
if v == "" {
v = "unknown"
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" {
v = info.Main.Version
}
}
if commit != "" {
v = fmt.Sprintf("%s (commit %s, built %s)", v, commit, date)
}
return "go-bind-plugin " + v
}
func main() {
logger := log.New(os.Stderr, "go-bind-plugin ", log.Ltime)
config := cli.Config{}
flagset := flag.NewFlagSet("go-bind-plugin", flag.ContinueOnError)
flagset.StringVar(&config.PluginPath, "plugin-path", "", "Path to plugin (.so file)")
flagset.StringVar(&config.PluginPackage, "plugin-package", "", "Plugin package (as accepted by go build); enables source-based analysis")
flagset.StringVar(&config.OutputName, "output-name", "PluginAPI", "Output struct name")
flagset.StringVar(&config.OutputPath, "output-path", "plugin_api.go", "Output file path")
flagset.BoolVar(&config.DereferenceVariables, "dereference-vars", false, "Dereference plugin variables")
flagset.BoolVar(&config.CheckSha256, "sha256", false, "Write plugin's sha256 checksum to wrapper and validate it when loading it")
flagset.BoolVar(&config.FormatCode, "format", true, "Format generated output file with gofmt")
flagset.BoolVar(&config.ForcePluginRebuild, "rebuild", false, "Rebuild plugin on every run")
flagset.StringVar(&config.OutputPackage, "output-package", "main", "Output package (can be derived from output-path)")
flagset.BoolVar(&config.HideVariables, "hide-vars", false, "Do not export plugin variables")
flagset.BoolVar(&config.AsInterface, "interface", false, "Generate and return interface instead of struct (turns on -hide-vars)")
showVersion := flagset.Bool("version", false, "Print version and exit")
if err := flagset.Parse(os.Args[1:]); err != nil {
logger.Fatal(err)
}
if *showVersion {
fmt.Println(versionString())
return
}
cli, err := cli.New(config, logger)
if err != nil {
logger.Fatal(err)
}
if err := cli.GenerateFile(); err != nil {
logger.Fatal(err)
}
}