Parcourir la source

generator: Accept bare names for builtin plugins on the cli

For plugins passed on the CLI, accept the bare name (eg "dns") for core
plugins, for simpler invocations for testing eg `./coredhcp-generator dns file`
The -from option (using a separate file) still requires the full import
path

Signed-off-by: Anatole Denis <anatole@unverle.fr>
Anatole Denis il y a 5 ans
Parent
commit
ae368fd230
1 fichiers modifiés avec 11 ajouts et 0 suppressions
  1. 11 0
      cmds/coredhcp-generator/main.go

+ 11 - 0
cmds/coredhcp-generator/main.go

@@ -18,6 +18,7 @@ import (
 
 const (
 	defaultTemplateFile = "coredhcp.go.template"
+	importBase          = "github.com/coredhcp/coredhcp/"
 )
 
 var (
@@ -52,6 +53,16 @@ func main() {
 		if pl == "" {
 			continue
 		}
+		if !strings.ContainsRune(pl, '/') {
+			// A bare name was specified, not a full import path.
+			// Coredhcp plugins aren't in the standard library, and it's unlikely someone
+			// would put them at the base of $GOPATH/src.
+			// Assume this is one of the builtin plugins. If needed, use the -from option
+			// which always requires (and uses) exact paths
+
+			// XXX: we could also look into github.com/coredhcp/plugins
+			pl = importBase + pl
+		}
 		plugins[pl] = true
 	}
 	if *flagFromFile != "" {