Skip to content

Commit

Permalink
Merge pull request #81 from pwittrock/master
Browse files Browse the repository at this point in the history
apiserver-boot parse --domain flag from pkg/apis/doc.go when not spec…
  • Loading branch information
Phillip Wittrock authored Jun 24, 2017
2 parents b9f652e + 999a6c0 commit c903a15
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
18 changes: 9 additions & 9 deletions cmd/apiserver-boot/boot/create_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func RunCreateResource(cmd *cobra.Command, args []string) {
}

if len(domain) == 0 {
log.Fatal("apiserver-boot create-resource requires the --domain flag")
domain = getDomain()
}
if len(groupName) == 0 {
log.Fatal("apiserver-boot create-resource requires the --group flag")
Expand Down Expand Up @@ -165,14 +165,14 @@ func createResource(boilerplate string) {
}

type resourceTemplateArgs struct {
BoilerPlate string
Domain string
Group string
Version string
Kind string
Resource string
Repo string
PluralizedKind string
BoilerPlate string
Domain string
Group string
Version string
Kind string
Resource string
Repo string
PluralizedKind string
NonNamespacedKind bool
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/apiserver-boot/boot/create_resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func RunCreateGroup(cmd *cobra.Command, args []string) {
}

if len(domain) == 0 {
log.Fatalf("apiserver-boot create-group requires the --domain flag")
domain = getDomain()
}
if len(groupName) == 0 {
log.Fatalf("apiserver-boot create-group requires the --groupName flag")
Expand Down
2 changes: 1 addition & 1 deletion cmd/apiserver-boot/boot/create_resource_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func RunCreateVersion(cmd *cobra.Command, args []string) {
}

if len(domain) == 0 {
log.Fatalf("apiserver-boot create-version requires the --domain flag")
domain = getDomain()
}
if len(groupName) == 0 {
log.Fatalf("apiserver-boot create-version requires the --group flag")
Expand Down
19 changes: 17 additions & 2 deletions cmd/apiserver-boot/boot/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"text/template"

"github.com/markbates/inflect"
)

Expand Down Expand Up @@ -57,8 +59,8 @@ func writeIfNotFound(path, templateName, templateValue string, data interface{})

t := template.Must(template.New(templateName).Funcs(
template.FuncMap{
"title": strings.Title,
"lower": strings.ToLower,
"title": strings.Title,
"lower": strings.ToLower,
"plural": inflect.NewDefaultRuleset().Pluralize,
},
).Parse(templateValue))
Expand Down Expand Up @@ -107,6 +109,19 @@ func getCopyright() string {
}
}

func getDomain() string {
b, err := ioutil.ReadFile(filepath.Join("pkg", "apis", "doc.go"))
if err != nil {
log.Fatalf("Could not find pkg/apis/doc.go. First run `apiserver-boot init --domain <domain>`.")
}
r := regexp.MustCompile("\\+domain=(.*)")
l := r.FindSubmatch(b)
if len(l) < 2 {
log.Fatalf("pkg/apis/doc.go does not contain the domain (// +domain=.*)", l)
}
return string(l[1])
}

func create(path string) {
f, err := os.Create(path)
if err != nil {
Expand Down

0 comments on commit c903a15

Please sign in to comment.