1+ // Copyright 2024 The Carvel Authors.
2+ // SPDX-License-Identifier: Apache-2.0
3+
14package cmd
25
36import (
@@ -14,7 +17,7 @@ import (
1417 ctlcache "carvel.dev/vendir/pkg/vendir/fetch/cache"
1518)
1619
17- func NewBaselineOptions (ui ui.UI ) * BaselineOptions {
20+ func NewBaselineOptions (ui ui.UI ) * BaselineOptions { //nolint:revive
1821 return & BaselineOptions {ui : ui }
1922}
2023
@@ -29,10 +32,15 @@ func NewBaselineCmd(o *BaselineOptions) *cobra.Command {
2932 & o .Yes , "yes" , "y" , false ,
3033 "If true, automatically answer 'yes' to all the questions" )
3134
32- cmd .Flags ().StringSliceVarP (& o .Files , "file" , "f" , []string {defaultConfigName }, "Set configuration file" )
33- cmd .Flags ().StringVar (& o .LockFile , "lock-file" , defaultLockName , "Set lock file" )
34- cmd .Flags ().StringVar (& o .Chdir , "chdir" , "" , "Set current directory for process" )
35- cmd .Flags ().BoolVar (& o .PreferSHA , "prefer-sha" , false , "Prefer sha instead of tags" )
35+ cmd .Flags ().StringSliceVarP (
36+ & o .Files , "file" , "f" , []string {defaultConfigName },
37+ "Set configuration file" )
38+ cmd .Flags ().StringVar (
39+ & o .LockFile , "lock-file" , defaultLockName , "Set lock file" )
40+ cmd .Flags ().StringVar (
41+ & o .Chdir , "chdir" , "" , "Set current directory for process" )
42+ cmd .Flags ().BoolVar (
43+ & o .PreferSHA , "prefer-sha" , false , "Prefer sha instead of tags" )
3644 cmd .Flags ().BoolVar (& o .DryRun , "dry-run" , false , "List what would be done" )
3745
3846 return & cmd
@@ -53,7 +61,7 @@ type BaselineOptions struct {
5361}
5462
5563func (o * BaselineOptions ) Run () error {
56- if len (o .Chdir ) > 0 {
64+ if len (o .Chdir ) > 0 { //nolint:revive
5765 err := os .Chdir (o .Chdir )
5866 if err != nil {
5967 return fmt .Errorf ("Running chdir: %s" , err )
@@ -91,19 +99,23 @@ func (o *BaselineOptions) Run() error {
9199 newRefs := make (map [string ]string )
92100
93101 for _ , status := range statusMap {
94- if ! status .MatchTarget () || ! o .PreferSHA && ! status .MatchTargetTag () && len (status .Ref .Tags ) != 0 {
102+ if ! status .MatchTarget () ||
103+ ! o .PreferSHA &&
104+ ! status .MatchTargetTag () &&
105+ len (status .Ref .Tags ) != 0 { //nolint:revive
95106 var newRef string
96- if o .PreferSHA || len (status .Ref .Tags ) == 0 {
107+ if o .PreferSHA || len (status .Ref .Tags ) == 0 { //nolint:revive
97108 newRef = status .Ref .SHA
98109 } else {
99- newRef = status .Ref .Tags [0 ]
110+ newRef = status .Ref .Tags [0 ] //nolint:revive
100111 }
101112 newRefs [status .Path ()] = newRef
102113 }
103114 }
104115
105- if len (newRefs ) == 0 {
106- o .ui .PrintLinef ("All references already match current state, no update needed" )
116+ if len (newRefs ) == 0 { //nolint:revive
117+ o .ui .PrintLinef (
118+ "All references already match current state, no update needed" )
107119
108120 return nil
109121 }
@@ -114,7 +126,9 @@ func (o *BaselineOptions) Run() error {
114126 if newRef != "" {
115127 newRef = " -> " + newRef
116128 }
117- o .ui .PrintLinef ("%s/%s: %s%s" , status .DirectoryPath , status .ContentPath , status .TargetRef , newRef )
129+ o .ui .PrintLinef (
130+ "%s/%s: %s%s" ,
131+ status .DirectoryPath , status .ContentPath , status .TargetRef , newRef )
118132 }
119133
120134 if ! o .DryRun {
@@ -152,7 +166,7 @@ func saveFile(fname string, doc *yaml.Node) error {
152166 }
153167
154168 enc := yaml .NewEncoder (f )
155- enc .SetIndent (2 )
169+ enc .SetIndent (2 ) //nolint:revive
156170 if err := enc .Encode (doc ); err != nil {
157171 _ = f .Close ()
158172
@@ -172,7 +186,7 @@ func updateRefs(fname string, newRefs map[string]string) error {
172186 panic ("expects the root node" )
173187 }
174188
175- top := doc .Content [0 ]
189+ top := doc .Content [0 ] //nolint:revive
176190 if top .Kind != yaml .MappingNode {
177191 panic ("top content must be a mapping" )
178192 }
@@ -193,14 +207,16 @@ func updateRefs(fname string, newRefs map[string]string) error {
193207 if hg := getMappingNodeChild (content , "hg" ); hg != nil {
194208 ref := getMappingNodeChild (hg , "ref" )
195209 if ref == nil {
196- return fmt .Errorf ("could not find 'ref' for '%s'" , fullPath )
210+ return fmt .Errorf (
211+ "could not find 'ref' for '%s'" , fullPath )
197212 }
198213 ref .Value = newRef
199214 }
200215 if git := getMappingNodeChild (content , "git" ); git != nil {
201216 ref := getMappingNodeChild (git , "ref" )
202217 if ref == nil {
203- return fmt .Errorf ("could not find 'ref' for '%s'" , fullPath )
218+ return fmt .Errorf (
219+ "could not find 'ref' for '%s'" , fullPath )
204220 }
205221 ref .Value = newRef
206222 }
@@ -212,9 +228,9 @@ func updateRefs(fname string, newRefs map[string]string) error {
212228}
213229
214230func getMappingNodeChild (node * yaml.Node , name string ) * yaml.Node {
215- for i := 0 ; i < len (node .Content ); i += 2 {
231+ for i := 0 ; i < len (node .Content ); i += 2 { //nolint:revive
216232 if node .Content [i ].Value == name {
217- return node .Content [i + 1 ]
233+ return node .Content [i + 1 ] //nolint:revive
218234 }
219235 }
220236
0 commit comments