@@ -16,9 +16,10 @@ import (
1616
1717func configCmd (o * Options ) (* cobra.Command , error ) {
1818 c := & cobra.Command {
19- Use : "config" ,
20- Short : "configure a lab" ,
21- Long : "configure a lab based on templates and variables from the topology definition file\n reference: https://containerlab.dev/cmd/config/" ,
19+ Use : "config" ,
20+ Short : "configure a lab" ,
21+ Long : "configure a lab based on templates and variables from the topology definition " +
22+ "file\n reference: https://containerlab.dev/cmd/config/" ,
2223 Aliases : []string {"conf" },
2324 ValidArgs : []string {"commit" , "send" , "compare" , "template" },
2425 SilenceUsage : true ,
@@ -105,9 +106,10 @@ func configSubCmds(c *cobra.Command, o *Options) {
105106 compareC .Flags ().AddFlagSet (c .Flags ())
106107
107108 templateC := & cobra.Command {
108- Use : "template" ,
109- Short : "render a template" ,
110- Long : "render a template based on variables from the topology definition file\n reference: https://containerlab.dev/cmd/config/template" ,
109+ Use : "template" ,
110+ Short : "render a template" ,
111+ Long : "render a template based on variables from the topology definition file\n " +
112+ "reference: https://containerlab.dev/cmd/config/template" ,
111113 Aliases : []string {"conf" },
112114 SilenceUsage : true ,
113115 RunE : func (_ * cobra.Command , _ []string ) error {
@@ -117,8 +119,13 @@ func configSubCmds(c *cobra.Command, o *Options) {
117119
118120 c .AddCommand (templateC )
119121 templateC .Flags ().AddFlagSet (c .Flags ())
120- templateC .Flags ().BoolVarP (& o .Config .TemplateVarOnly , "vars" , "v" , o .Config .TemplateVarOnly ,
121- "show variable used for template rendering" )
122+ templateC .Flags ().BoolVarP (
123+ & o .Config .TemplateVarOnly ,
124+ "vars" ,
125+ "v" ,
126+ o .Config .TemplateVarOnly ,
127+ "show variable used for template rendering" ,
128+ )
122129 templateC .Flags ().SortFlags = false
123130}
124131
@@ -128,12 +135,7 @@ func configRun(_ *cobra.Command, args []string, o *Options) error {
128135 transport .DebugCount = o .Global .DebugCount
129136 clabcoreconfig .DebugCount = o .Global .DebugCount
130137
131- c , err := clabcore .NewContainerLab (
132- clabcore .WithTimeout (o .Global .Timeout ),
133- clabcore .WithTopoPath (o .Global .TopologyFile , o .Global .VarsFile ),
134- clabcore .WithNodeFilter (o .Filter .NodeFilter ),
135- clabcore .WithDebug (o .Global .DebugCount > 0 ),
136- )
138+ c , err := clabcore .NewContainerLab (o .ToClabOptions ()... )
137139 if err != nil {
138140 return err
139141 }
@@ -168,12 +170,14 @@ func configRun(_ *cobra.Command, args []string, o *Options) error {
168170 }
169171
170172 var wg sync.WaitGroup
173+
171174 deploy := func (n string ) {
172175 defer wg .Done ()
173176
174177 cs , ok := allConfig [n ]
175178 if ! ok {
176179 log .Errorf ("Invalid node in filter: %s" , n )
180+
177181 return
178182 }
179183
@@ -182,7 +186,9 @@ func configRun(_ *cobra.Command, args []string, o *Options) error {
182186 log .Warnf ("%s: %s" , cs .TargetNode .ShortName , err )
183187 }
184188 }
189+
185190 wg .Add (len (o .Filter .LabelFilter ))
191+
186192 for _ , node := range o .Filter .LabelFilter {
187193 // On debug this will not be executed concurrently
188194 if log .GetLevel () == (log .DebugLevel ) {
@@ -191,6 +197,7 @@ func configRun(_ *cobra.Command, args []string, o *Options) error {
191197 go deploy (node )
192198 }
193199 }
200+
194201 wg .Wait ()
195202
196203 return nil
@@ -201,11 +208,7 @@ func configTemplate(o *Options) error {
201208
202209 clabcoreconfig .DebugCount = o .Global .DebugCount
203210
204- c , err := clabcore .NewContainerLab (
205- clabcore .WithTimeout (o .Global .Timeout ),
206- clabcore .WithTopoPath (o .Global .TopologyFile , o .Global .VarsFile ),
207- clabcore .WithDebug (o .Global .DebugCount > 0 ),
208- )
211+ c , err := clabcore .NewContainerLab (o .ToClabOptions ()... )
209212 if err != nil {
210213 return err
211214 }
@@ -216,11 +219,13 @@ func configTemplate(o *Options) error {
216219 }
217220
218221 allConfig := clabcoreconfig .PrepareVars (c )
222+
219223 if o .Config .TemplateVarOnly {
220224 for _ , n := range o .Filter .LabelFilter {
221225 conf := allConfig [n ]
222226 conf .Print (true , false )
223227 }
228+
224229 return nil
225230 }
226231
@@ -241,17 +246,21 @@ func validateFilter(nodes map[string]clabnodes.Node, o *Options) error {
241246 for n := range nodes {
242247 o .Filter .LabelFilter = append (o .Filter .LabelFilter , n )
243248 }
249+
244250 return nil
245251 }
246252
247253 var mis []string
254+
248255 for _ , nn := range o .Filter .LabelFilter {
249256 if _ , ok := nodes [nn ]; ! ok {
250257 mis = append (mis , nn )
251258 }
252259 }
260+
253261 if len (mis ) > 0 {
254262 return fmt .Errorf ("invalid nodes in filter: %s" , strings .Join (mis , ", " ))
255263 }
264+
256265 return nil
257266}
0 commit comments