Skip to content

Commit 1da6a1d

Browse files
committed
Merge pull request #84 from appropriate/allow-multiple-config-flags
Support passing -config multiple times
2 parents 243cb0d + 202074a commit 1da6a1d

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

docker-gen.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
docker "github.com/fsouza/go-dockerclient"
1616
)
1717

18+
type stringslice []string
19+
1820
var (
1921
buildVersion string
2022
version bool
@@ -23,7 +25,7 @@ var (
2325
notifySigHUPContainerID string
2426
onlyExposed bool
2527
onlyPublished bool
26-
configFile string
28+
configFiles stringslice
2729
configs ConfigFile
2830
interval int
2931
endpoint string
@@ -77,6 +79,16 @@ type SwarmNode struct {
7779
Address Address
7880
}
7981

82+
func (strings *stringslice) String() string {
83+
return "[]"
84+
}
85+
86+
func (strings *stringslice) Set(value string) error {
87+
// TODO: Throw an error for duplicate `dest`
88+
*strings = append(*strings, value)
89+
return nil
90+
}
91+
8092
func (i *DockerImage) String() string {
8193
ret := i.Repository
8294
if i.Registry != "" {
@@ -338,7 +350,7 @@ func initFlags() {
338350
flag.BoolVar(&onlyPublished, "only-published", false, "only include containers with published ports (implies -only-exposed)")
339351
flag.StringVar(&notifyCmd, "notify", "", "run command after template is regenerated")
340352
flag.StringVar(&notifySigHUPContainerID, "notify-sighup", "", "send HUP signal to container. Equivalent to `docker kill -s HUP container-ID`")
341-
flag.StringVar(&configFile, "config", "", "config file with template directives")
353+
flag.Var(&configFiles, "config", "config files with template directives. Config files will be merged if this option is specified multiple times.")
342354
flag.IntVar(&interval, "interval", 0, "notify command interval (s)")
343355
flag.StringVar(&endpoint, "endpoint", "", "docker api endpoint")
344356
flag.StringVar(&tlsCert, "tlscert", "", "path to TLS client certificate file")
@@ -356,15 +368,17 @@ func main() {
356368
return
357369
}
358370

359-
if flag.NArg() < 1 && configFile == "" {
371+
if flag.NArg() < 1 && len(configFiles) == 0 {
360372
usage()
361373
os.Exit(1)
362374
}
363375

364-
if configFile != "" {
365-
err := loadConfig(configFile)
366-
if err != nil {
367-
log.Fatalf("error loading config %s: %s\n", configFile, err)
376+
if len(configFiles) > 0 {
377+
for _, configFile := range configFiles {
378+
err := loadConfig(configFile)
379+
if err != nil {
380+
log.Fatalf("error loading config %s: %s\n", configFile, err)
381+
}
368382
}
369383
} else {
370384
config := Config{

0 commit comments

Comments
 (0)