MCPcopy
hub / github.com/urfave/cli / Set

Method Set

flag_impl.go:180–211  ·  view source on GitHub ↗

Set applies given value from string

(_ string, val string)

Source from the content-addressed store, hash-verified

178
179// Set applies given value from string
180func (f *FlagBase[T, C, V]) Set(_ string, val string) error {
181 tracef("apply (flag=%[1]q)", f.Name)
182
183 // TODO move this phase into a separate flag initialization function
184 // if flag has been applied previously then it would have already been set
185 // from env or file. So no need to apply the env set again. However
186 // lots of units tests prior to persistent flags assumed that the
187 // flag can be applied to different flag sets multiple times while still
188 // keeping the env set.
189 if !f.applied {
190 if err := f.PreParse(); err != nil {
191 return err
192 }
193 f.applied = true
194 }
195
196 if f.count == 1 && f.OnlyOnce {
197 return fmt.Errorf("can't duplicate this flag")
198 }
199
200 f.count++
201 if err := f.value.Set(val); err != nil {
202 return err
203 }
204 f.hasBeenSet = true
205 if f.Validator != nil {
206 if err := f.Validator(f.value.Get().(T)); err != nil {
207 return err
208 }
209 }
210 return nil
211}
212
213func (f *FlagBase[T, C, V]) Get() any {
214 if f.value != nil {

Callers 1

PostParseMethod · 0.95

Calls 4

PreParseMethod · 0.95
tracefFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected