Remove template files, make them const strings instead

master
Harshavardhana 10 years ago
parent 024b3a29d3
commit 0212079cd5
  1. 40
      cmd/new-cmd/new-cmd-flags.go
  2. 10
      cmd/new-cmd/new-cmd.go
  3. 95
      cmd/new-cmd/templates.go
  4. 13
      cmd/new-cmd/templates/README.tmpl
  5. 31
      cmd/new-cmd/templates/main.tmpl
  6. 41
      cmd/new-cmd/templates/options.tmpl

@ -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)

@ -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: "",

@ -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
`
)

@ -1,13 +0,0 @@
% MINIO(1) Minio Manual
% Minio community
% {{.Month}} {{.Year}}
# NAME
{{.Name}} - {{.Usage}}
# SYNOPSIS
# DESCRIPTION
# EXAMPLES
# AUTHORS

@ -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)
}

@ -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}}
Loading…
Cancel
Save