From 0212079cd5a2dfcf53a40807fdbb988c23e258ab Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 1 Jan 2015 17:31:43 -0800 Subject: [PATCH] Remove template files, make them const strings instead --- cmd/new-cmd/new-cmd-flags.go | 40 ++----------- cmd/new-cmd/new-cmd.go | 10 ---- cmd/new-cmd/templates.go | 95 ++++++++++++++++++++++++++++++ cmd/new-cmd/templates/README.tmpl | 13 ---- cmd/new-cmd/templates/main.tmpl | 31 ---------- cmd/new-cmd/templates/options.tmpl | 41 ------------- 6 files changed, 101 insertions(+), 129 deletions(-) create mode 100644 cmd/new-cmd/templates.go delete mode 100644 cmd/new-cmd/templates/README.tmpl delete mode 100644 cmd/new-cmd/templates/main.tmpl delete mode 100644 cmd/new-cmd/templates/options.tmpl diff --git a/cmd/new-cmd/new-cmd-flags.go b/cmd/new-cmd/new-cmd-flags.go index 14d7e6afa..746d2345c 100644 --- a/cmd/new-cmd/new-cmd-flags.go +++ b/cmd/new-cmd/new-cmd-flags.go @@ -3,7 +3,6 @@ package main import ( "log" "os" - "path" "strings" "text/template" @@ -34,36 +33,9 @@ func parseInput(c *cli.Context) { commandUsage = c.String("usage") } - var templatePath string - if c.String("path") != "" { - templatePath = c.String("path") - } - - gopath := os.Getenv("GOPATH") - - var mainTemplatePath, optionsTemplatePath, readmeTemplatePath string - if templatePath == TEMPLATEREPO { - mainTemplatePath = path.Join(gopath, templatePath, "main.tmpl") - optionsTemplatePath = path.Join(gopath, templatePath, "options.tmpl") - readmeTemplatePath = path.Join(gopath, templatePath, "README.tmpl") - } else { - mainTemplatePath = path.Join(templatePath, "main.tmpl") - optionsTemplatePath = path.Join(templatePath, "options.tmpl") - readmeTemplatePath = path.Join(templatePath, "README.tmpl") - } - if _, err := os.Stat(mainTemplatePath); err != nil { - log.Fatal(err) - } - if _, err := os.Stat(optionsTemplatePath); err != nil { - log.Fatal(err) - } - if _, err := os.Stat(readmeTemplatePath); err != nil { - log.Fatal(err) - } - - var mainTemplate = template.Must(template.ParseFiles(mainTemplatePath)) - var optionsTemplate = template.Must(template.ParseFiles(optionsTemplatePath)) - var readmeTemplate = template.Must(template.ParseFiles(readmeTemplatePath)) + var mainObject = template.Must(template.New("main").Parse(commandTemplate)) + var optionsObject = template.Must(template.New("options").Parse(optionsTemplate)) + var readmeObject = template.Must(template.New("readme").Parse(readmeTemplate)) err := os.Mkdir(commandName, 0755) utils.Assert(err) @@ -72,17 +44,17 @@ func parseInput(c *cli.Context) { optionsGo := source{ Name: commandName + "-options.go", - TempLate: *optionsTemplate, + TempLate: *optionsObject, } readmeMd := source{ Name: commandName + ".md", - TempLate: *readmeTemplate, + TempLate: *readmeObject, } mainGo := source{ Name: commandName + ".go", - TempLate: *mainTemplate, + TempLate: *mainObject, } err = readmeMd.get(commandName, command) diff --git a/cmd/new-cmd/new-cmd.go b/cmd/new-cmd/new-cmd.go index 272eb94df..f8d4abcb3 100644 --- a/cmd/new-cmd/new-cmd.go +++ b/cmd/new-cmd/new-cmd.go @@ -15,11 +15,6 @@ type source struct { TempLate template.Template } -const ( - // Relative path from GOPATH default - TEMPLATEREPO = "/src/github.com/minio-io/minio/cmd/new-cmd/templates/" -) - type option struct { Name string Definename string @@ -84,11 +79,6 @@ func main() { Value: "", Usage: "Command-separated list of options to build", }, - cli.StringFlag{ - Name: "path", - Value: TEMPLATEREPO, - Usage: "Non standard templates path", - }, cli.StringFlag{ Name: "usage", Value: "", diff --git a/cmd/new-cmd/templates.go b/cmd/new-cmd/templates.go new file mode 100644 index 000000000..4cf68b7fd --- /dev/null +++ b/cmd/new-cmd/templates.go @@ -0,0 +1,95 @@ +package main + +const ( + commandTemplate = ` +/* + * Mini Object Storage, (C) 2014 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "os" + + "github.com/codegangsta/cli" +) + +func main() { + app := cli.NewApp() + app.Name = "{{.Name}}" + app.Usage = "{{.Usage}}" + app.Commands = Options + app.Author = "Minio" + app.Run(os.Args) +} +` + optionsTemplate = ` +/* + * Mini Object Storage, (C) 2014 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "github.com/codegangsta/cli" +) + +var Options = []cli.Command{ + {{range .Options}}{{.Definename}}, + {{end}} +} + +{{range .Options}} +var {{.Definename}} = cli.Command{ + Name: "{{.Name}}", + Usage: "", + Description: "", + Action: {{.Functionname}}, +} +{{end}} + +{{range .Options}} +func {{.Functionname}}(c *cli.Context) { +} +{{end}} +` + readmeTemplate = ` +% MINIO(1) Minio Manual +% Minio community +% {{.Month}} {{.Year}} +# NAME +{{.Name}} - {{.Usage}} + +# SYNOPSIS + +# DESCRIPTION + +# EXAMPLES + +# AUTHORS +` +) diff --git a/cmd/new-cmd/templates/README.tmpl b/cmd/new-cmd/templates/README.tmpl deleted file mode 100644 index 5a7e122f2..000000000 --- a/cmd/new-cmd/templates/README.tmpl +++ /dev/null @@ -1,13 +0,0 @@ -% MINIO(1) Minio Manual -% Minio community -% {{.Month}} {{.Year}} -# NAME -{{.Name}} - {{.Usage}} - -# SYNOPSIS - -# DESCRIPTION - -# EXAMPLES - -# AUTHORS \ No newline at end of file diff --git a/cmd/new-cmd/templates/main.tmpl b/cmd/new-cmd/templates/main.tmpl deleted file mode 100644 index b4dbcc4fa..000000000 --- a/cmd/new-cmd/templates/main.tmpl +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Mini Object Storage, (C) 2014 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - "os" - - "github.com/codegangsta/cli" -) - -func main() { - app := cli.NewApp() - app.Name = "{{.Name}}" - app.Usage = "{{.Usage}}" - app.Commands = Options - app.Run(os.Args) -} diff --git a/cmd/new-cmd/templates/options.tmpl b/cmd/new-cmd/templates/options.tmpl deleted file mode 100644 index 221b43017..000000000 --- a/cmd/new-cmd/templates/options.tmpl +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Mini Object Storage, (C) 2014 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - "github.com/codegangsta/cli" -) - -var Options = []cli.Command{ - {{range .Options}}{{.Definename}}, - {{end}} -} - -{{range .Options}} -var {{.Definename}} = cli.Command{ - Name: "{{.Name}}", - Usage: "", - Description: ` -`, - Action: {{.Functionname}}, -} -{{end}} - -{{range .Options}} -func {{.Functionname}}(c *cli.Context) { -} -{{end}}