blob: 3c7e1e3de18ad2468cdfc5087c021022f6c14745 [file] [log] [blame]
Dan Willemsenfdeb7242015-07-24 16:53:27 -07001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import (
18 "bytes"
19 "flag"
20 "fmt"
21 "io/ioutil"
22 "os"
23 "path/filepath"
24 "text/template"
25)
26
27var (
28 output = flag.String("o", "", "output filename")
29 pkg = flag.String("p", "main", "package name")
30)
31
32func main() {
33 flag.Parse()
34
35 if flag.NArg() == 0 {
36 fmt.Fprintln(os.Stderr, "error: must pass at least one input")
37 os.Exit(1)
38 }
39
40 buf := &bytes.Buffer{}
41
42 err := pluginTmpl.Execute(buf, struct {
43 Package string
44 Plugins []string
45 }{
46 filepath.Base(*pkg),
47 flag.Args(),
48 })
49 if err != nil {
50 panic(err)
51 }
52
53 err = ioutil.WriteFile(*output, buf.Bytes(), 0666)
54 if err != nil {
55 panic(err)
56 }
57}
58
59var pluginTmpl = template.Must(template.New("pluginloader").Parse(`
60package {{.Package}}
61
62import (
63{{range .Plugins}}
64 _ "{{.}}"
65{{end}}
66)
67`))