mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
Unify generation of data for template expansion using ProjectToMap()
This commit is contained in:
parent
15eff95ef4
commit
e1be966340
1 changed files with 2 additions and 9 deletions
|
@ -16,7 +16,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -117,10 +116,7 @@ func main() {
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
data := make(map[string]interface{})
|
data := project.ProjectToMap()
|
||||||
data["copyright"] = copyrightLine()
|
|
||||||
data["license"] = project.License().Header
|
|
||||||
data["importpath"] = path.Join(project.Name(), filepath.Base(project.CmdPath()))
|
|
||||||
|
|
||||||
mainScript, err := executeTemplate(mainTemplate, data)
|
mainScript, err := executeTemplate(mainTemplate, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -215,11 +211,8 @@ func initConfig() {
|
||||||
}{{ end }}
|
}{{ end }}
|
||||||
`
|
`
|
||||||
|
|
||||||
data := make(map[string]interface{})
|
data := project.ProjectToMap()
|
||||||
data["copyright"] = copyrightLine()
|
|
||||||
data["viper"] = viper.GetBool("useViper")
|
data["viper"] = viper.GetBool("useViper")
|
||||||
data["license"] = project.License().Header
|
|
||||||
data["appName"] = path.Base(project.Name())
|
|
||||||
|
|
||||||
rootCmdScript, err := executeTemplate(template, data)
|
rootCmdScript, err := executeTemplate(template, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue