Skip to content

Commit

Permalink
paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerza committed Jun 9, 2021
1 parent 9110c1c commit 16053d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions clab/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var TemplateNames []string

// path to additional templates
var TemplatePath string
var TemplatePaths []string

type NodeConfig struct {
TargetNode *types.Node
Expand All @@ -29,7 +29,14 @@ type NodeConfig struct {
func RenderAll(nodes map[string]*types.Node, links map[int]*types.Link) (map[string]*NodeConfig, error) {
res := make(map[string]*NodeConfig)

tmpl, err := template.New("", template.SearchPath(TemplatePath))
if len(TemplateNames) == 0 {
return nil, fmt.Errorf("please specify one of more templates with --template-list")
}
if len(TemplatePaths) == 0 {
return nil, fmt.Errorf("please specify one of more paths with --template-path")
}

tmpl, err := template.New("", template.SearchPath(TemplatePaths...))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var configCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(configCmd)
configCmd.Flags().StringVarP(&config.TemplatePath, "template-path", "p", "", "directory with templates used to render config")
configCmd.Flags().StringSliceVarP(&config.TemplatePaths, "template-path", "p", []string{}, "comma separated list of paths to search for templates")
configCmd.MarkFlagDirname("template-path")
configCmd.Flags().StringSliceVarP(&config.TemplateNames, "template-list", "l", []string{}, "comma separated list of template names to render")
configCmd.Flags().IntVarP(&printLines, "check", "c", 0, "render dry-run & print n lines of config")
Expand Down

0 comments on commit 16053d3

Please sign in to comment.