flag_generated.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. package cli
  2. import (
  3. "flag"
  4. "strconv"
  5. "time"
  6. )
  7. // WARNING: This file is generated!
  8. // BoolFlag is a flag with type bool
  9. type BoolFlag struct {
  10. Name string
  11. Usage string
  12. EnvVar string
  13. FilePath string
  14. Hidden bool
  15. Destination *bool
  16. }
  17. // String returns a readable representation of this value
  18. // (for usage defaults)
  19. func (f BoolFlag) String() string {
  20. return FlagStringer(f)
  21. }
  22. // GetName returns the name of the flag
  23. func (f BoolFlag) GetName() string {
  24. return f.Name
  25. }
  26. // Bool looks up the value of a local BoolFlag, returns
  27. // false if not found
  28. func (c *Context) Bool(name string) bool {
  29. return lookupBool(name, c.flagSet)
  30. }
  31. // GlobalBool looks up the value of a global BoolFlag, returns
  32. // false if not found
  33. func (c *Context) GlobalBool(name string) bool {
  34. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  35. return lookupBool(name, fs)
  36. }
  37. return false
  38. }
  39. func lookupBool(name string, set *flag.FlagSet) bool {
  40. f := set.Lookup(name)
  41. if f != nil {
  42. parsed, err := strconv.ParseBool(f.Value.String())
  43. if err != nil {
  44. return false
  45. }
  46. return parsed
  47. }
  48. return false
  49. }
  50. // BoolTFlag is a flag with type bool that is true by default
  51. type BoolTFlag struct {
  52. Name string
  53. Usage string
  54. EnvVar string
  55. FilePath string
  56. Hidden bool
  57. Destination *bool
  58. }
  59. // String returns a readable representation of this value
  60. // (for usage defaults)
  61. func (f BoolTFlag) String() string {
  62. return FlagStringer(f)
  63. }
  64. // GetName returns the name of the flag
  65. func (f BoolTFlag) GetName() string {
  66. return f.Name
  67. }
  68. // BoolT looks up the value of a local BoolTFlag, returns
  69. // false if not found
  70. func (c *Context) BoolT(name string) bool {
  71. return lookupBoolT(name, c.flagSet)
  72. }
  73. // GlobalBoolT looks up the value of a global BoolTFlag, returns
  74. // false if not found
  75. func (c *Context) GlobalBoolT(name string) bool {
  76. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  77. return lookupBoolT(name, fs)
  78. }
  79. return false
  80. }
  81. func lookupBoolT(name string, set *flag.FlagSet) bool {
  82. f := set.Lookup(name)
  83. if f != nil {
  84. parsed, err := strconv.ParseBool(f.Value.String())
  85. if err != nil {
  86. return false
  87. }
  88. return parsed
  89. }
  90. return false
  91. }
  92. // DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration)
  93. type DurationFlag struct {
  94. Name string
  95. Usage string
  96. EnvVar string
  97. FilePath string
  98. Hidden bool
  99. Value time.Duration
  100. Destination *time.Duration
  101. }
  102. // String returns a readable representation of this value
  103. // (for usage defaults)
  104. func (f DurationFlag) String() string {
  105. return FlagStringer(f)
  106. }
  107. // GetName returns the name of the flag
  108. func (f DurationFlag) GetName() string {
  109. return f.Name
  110. }
  111. // Duration looks up the value of a local DurationFlag, returns
  112. // 0 if not found
  113. func (c *Context) Duration(name string) time.Duration {
  114. return lookupDuration(name, c.flagSet)
  115. }
  116. // GlobalDuration looks up the value of a global DurationFlag, returns
  117. // 0 if not found
  118. func (c *Context) GlobalDuration(name string) time.Duration {
  119. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  120. return lookupDuration(name, fs)
  121. }
  122. return 0
  123. }
  124. func lookupDuration(name string, set *flag.FlagSet) time.Duration {
  125. f := set.Lookup(name)
  126. if f != nil {
  127. parsed, err := time.ParseDuration(f.Value.String())
  128. if err != nil {
  129. return 0
  130. }
  131. return parsed
  132. }
  133. return 0
  134. }
  135. // Float64Flag is a flag with type float64
  136. type Float64Flag struct {
  137. Name string
  138. Usage string
  139. EnvVar string
  140. FilePath string
  141. Hidden bool
  142. Value float64
  143. Destination *float64
  144. }
  145. // String returns a readable representation of this value
  146. // (for usage defaults)
  147. func (f Float64Flag) String() string {
  148. return FlagStringer(f)
  149. }
  150. // GetName returns the name of the flag
  151. func (f Float64Flag) GetName() string {
  152. return f.Name
  153. }
  154. // Float64 looks up the value of a local Float64Flag, returns
  155. // 0 if not found
  156. func (c *Context) Float64(name string) float64 {
  157. return lookupFloat64(name, c.flagSet)
  158. }
  159. // GlobalFloat64 looks up the value of a global Float64Flag, returns
  160. // 0 if not found
  161. func (c *Context) GlobalFloat64(name string) float64 {
  162. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  163. return lookupFloat64(name, fs)
  164. }
  165. return 0
  166. }
  167. func lookupFloat64(name string, set *flag.FlagSet) float64 {
  168. f := set.Lookup(name)
  169. if f != nil {
  170. parsed, err := strconv.ParseFloat(f.Value.String(), 64)
  171. if err != nil {
  172. return 0
  173. }
  174. return parsed
  175. }
  176. return 0
  177. }
  178. // GenericFlag is a flag with type Generic
  179. type GenericFlag struct {
  180. Name string
  181. Usage string
  182. EnvVar string
  183. FilePath string
  184. Hidden bool
  185. Value Generic
  186. }
  187. // String returns a readable representation of this value
  188. // (for usage defaults)
  189. func (f GenericFlag) String() string {
  190. return FlagStringer(f)
  191. }
  192. // GetName returns the name of the flag
  193. func (f GenericFlag) GetName() string {
  194. return f.Name
  195. }
  196. // Generic looks up the value of a local GenericFlag, returns
  197. // nil if not found
  198. func (c *Context) Generic(name string) interface{} {
  199. return lookupGeneric(name, c.flagSet)
  200. }
  201. // GlobalGeneric looks up the value of a global GenericFlag, returns
  202. // nil if not found
  203. func (c *Context) GlobalGeneric(name string) interface{} {
  204. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  205. return lookupGeneric(name, fs)
  206. }
  207. return nil
  208. }
  209. func lookupGeneric(name string, set *flag.FlagSet) interface{} {
  210. f := set.Lookup(name)
  211. if f != nil {
  212. parsed, err := f.Value, error(nil)
  213. if err != nil {
  214. return nil
  215. }
  216. return parsed
  217. }
  218. return nil
  219. }
  220. // Int64Flag is a flag with type int64
  221. type Int64Flag struct {
  222. Name string
  223. Usage string
  224. EnvVar string
  225. FilePath string
  226. Hidden bool
  227. Value int64
  228. Destination *int64
  229. }
  230. // String returns a readable representation of this value
  231. // (for usage defaults)
  232. func (f Int64Flag) String() string {
  233. return FlagStringer(f)
  234. }
  235. // GetName returns the name of the flag
  236. func (f Int64Flag) GetName() string {
  237. return f.Name
  238. }
  239. // Int64 looks up the value of a local Int64Flag, returns
  240. // 0 if not found
  241. func (c *Context) Int64(name string) int64 {
  242. return lookupInt64(name, c.flagSet)
  243. }
  244. // GlobalInt64 looks up the value of a global Int64Flag, returns
  245. // 0 if not found
  246. func (c *Context) GlobalInt64(name string) int64 {
  247. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  248. return lookupInt64(name, fs)
  249. }
  250. return 0
  251. }
  252. func lookupInt64(name string, set *flag.FlagSet) int64 {
  253. f := set.Lookup(name)
  254. if f != nil {
  255. parsed, err := strconv.ParseInt(f.Value.String(), 0, 64)
  256. if err != nil {
  257. return 0
  258. }
  259. return parsed
  260. }
  261. return 0
  262. }
  263. // IntFlag is a flag with type int
  264. type IntFlag struct {
  265. Name string
  266. Usage string
  267. EnvVar string
  268. FilePath string
  269. Hidden bool
  270. Value int
  271. Destination *int
  272. }
  273. // String returns a readable representation of this value
  274. // (for usage defaults)
  275. func (f IntFlag) String() string {
  276. return FlagStringer(f)
  277. }
  278. // GetName returns the name of the flag
  279. func (f IntFlag) GetName() string {
  280. return f.Name
  281. }
  282. // Int looks up the value of a local IntFlag, returns
  283. // 0 if not found
  284. func (c *Context) Int(name string) int {
  285. return lookupInt(name, c.flagSet)
  286. }
  287. // GlobalInt looks up the value of a global IntFlag, returns
  288. // 0 if not found
  289. func (c *Context) GlobalInt(name string) int {
  290. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  291. return lookupInt(name, fs)
  292. }
  293. return 0
  294. }
  295. func lookupInt(name string, set *flag.FlagSet) int {
  296. f := set.Lookup(name)
  297. if f != nil {
  298. parsed, err := strconv.ParseInt(f.Value.String(), 0, 64)
  299. if err != nil {
  300. return 0
  301. }
  302. return int(parsed)
  303. }
  304. return 0
  305. }
  306. // IntSliceFlag is a flag with type *IntSlice
  307. type IntSliceFlag struct {
  308. Name string
  309. Usage string
  310. EnvVar string
  311. FilePath string
  312. Hidden bool
  313. Value *IntSlice
  314. }
  315. // String returns a readable representation of this value
  316. // (for usage defaults)
  317. func (f IntSliceFlag) String() string {
  318. return FlagStringer(f)
  319. }
  320. // GetName returns the name of the flag
  321. func (f IntSliceFlag) GetName() string {
  322. return f.Name
  323. }
  324. // IntSlice looks up the value of a local IntSliceFlag, returns
  325. // nil if not found
  326. func (c *Context) IntSlice(name string) []int {
  327. return lookupIntSlice(name, c.flagSet)
  328. }
  329. // GlobalIntSlice looks up the value of a global IntSliceFlag, returns
  330. // nil if not found
  331. func (c *Context) GlobalIntSlice(name string) []int {
  332. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  333. return lookupIntSlice(name, fs)
  334. }
  335. return nil
  336. }
  337. func lookupIntSlice(name string, set *flag.FlagSet) []int {
  338. f := set.Lookup(name)
  339. if f != nil {
  340. parsed, err := (f.Value.(*IntSlice)).Value(), error(nil)
  341. if err != nil {
  342. return nil
  343. }
  344. return parsed
  345. }
  346. return nil
  347. }
  348. // Int64SliceFlag is a flag with type *Int64Slice
  349. type Int64SliceFlag struct {
  350. Name string
  351. Usage string
  352. EnvVar string
  353. FilePath string
  354. Hidden bool
  355. Value *Int64Slice
  356. }
  357. // String returns a readable representation of this value
  358. // (for usage defaults)
  359. func (f Int64SliceFlag) String() string {
  360. return FlagStringer(f)
  361. }
  362. // GetName returns the name of the flag
  363. func (f Int64SliceFlag) GetName() string {
  364. return f.Name
  365. }
  366. // Int64Slice looks up the value of a local Int64SliceFlag, returns
  367. // nil if not found
  368. func (c *Context) Int64Slice(name string) []int64 {
  369. return lookupInt64Slice(name, c.flagSet)
  370. }
  371. // GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns
  372. // nil if not found
  373. func (c *Context) GlobalInt64Slice(name string) []int64 {
  374. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  375. return lookupInt64Slice(name, fs)
  376. }
  377. return nil
  378. }
  379. func lookupInt64Slice(name string, set *flag.FlagSet) []int64 {
  380. f := set.Lookup(name)
  381. if f != nil {
  382. parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil)
  383. if err != nil {
  384. return nil
  385. }
  386. return parsed
  387. }
  388. return nil
  389. }
  390. // StringFlag is a flag with type string
  391. type StringFlag struct {
  392. Name string
  393. Usage string
  394. EnvVar string
  395. FilePath string
  396. Hidden bool
  397. Value string
  398. Destination *string
  399. }
  400. // String returns a readable representation of this value
  401. // (for usage defaults)
  402. func (f StringFlag) String() string {
  403. return FlagStringer(f)
  404. }
  405. // GetName returns the name of the flag
  406. func (f StringFlag) GetName() string {
  407. return f.Name
  408. }
  409. // String looks up the value of a local StringFlag, returns
  410. // "" if not found
  411. func (c *Context) String(name string) string {
  412. return lookupString(name, c.flagSet)
  413. }
  414. // GlobalString looks up the value of a global StringFlag, returns
  415. // "" if not found
  416. func (c *Context) GlobalString(name string) string {
  417. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  418. return lookupString(name, fs)
  419. }
  420. return ""
  421. }
  422. func lookupString(name string, set *flag.FlagSet) string {
  423. f := set.Lookup(name)
  424. if f != nil {
  425. parsed, err := f.Value.String(), error(nil)
  426. if err != nil {
  427. return ""
  428. }
  429. return parsed
  430. }
  431. return ""
  432. }
  433. // StringSliceFlag is a flag with type *StringSlice
  434. type StringSliceFlag struct {
  435. Name string
  436. Usage string
  437. EnvVar string
  438. FilePath string
  439. Hidden bool
  440. Value *StringSlice
  441. }
  442. // String returns a readable representation of this value
  443. // (for usage defaults)
  444. func (f StringSliceFlag) String() string {
  445. return FlagStringer(f)
  446. }
  447. // GetName returns the name of the flag
  448. func (f StringSliceFlag) GetName() string {
  449. return f.Name
  450. }
  451. // StringSlice looks up the value of a local StringSliceFlag, returns
  452. // nil if not found
  453. func (c *Context) StringSlice(name string) []string {
  454. return lookupStringSlice(name, c.flagSet)
  455. }
  456. // GlobalStringSlice looks up the value of a global StringSliceFlag, returns
  457. // nil if not found
  458. func (c *Context) GlobalStringSlice(name string) []string {
  459. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  460. return lookupStringSlice(name, fs)
  461. }
  462. return nil
  463. }
  464. func lookupStringSlice(name string, set *flag.FlagSet) []string {
  465. f := set.Lookup(name)
  466. if f != nil {
  467. parsed, err := (f.Value.(*StringSlice)).Value(), error(nil)
  468. if err != nil {
  469. return nil
  470. }
  471. return parsed
  472. }
  473. return nil
  474. }
  475. // Uint64Flag is a flag with type uint64
  476. type Uint64Flag struct {
  477. Name string
  478. Usage string
  479. EnvVar string
  480. FilePath string
  481. Hidden bool
  482. Value uint64
  483. Destination *uint64
  484. }
  485. // String returns a readable representation of this value
  486. // (for usage defaults)
  487. func (f Uint64Flag) String() string {
  488. return FlagStringer(f)
  489. }
  490. // GetName returns the name of the flag
  491. func (f Uint64Flag) GetName() string {
  492. return f.Name
  493. }
  494. // Uint64 looks up the value of a local Uint64Flag, returns
  495. // 0 if not found
  496. func (c *Context) Uint64(name string) uint64 {
  497. return lookupUint64(name, c.flagSet)
  498. }
  499. // GlobalUint64 looks up the value of a global Uint64Flag, returns
  500. // 0 if not found
  501. func (c *Context) GlobalUint64(name string) uint64 {
  502. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  503. return lookupUint64(name, fs)
  504. }
  505. return 0
  506. }
  507. func lookupUint64(name string, set *flag.FlagSet) uint64 {
  508. f := set.Lookup(name)
  509. if f != nil {
  510. parsed, err := strconv.ParseUint(f.Value.String(), 0, 64)
  511. if err != nil {
  512. return 0
  513. }
  514. return parsed
  515. }
  516. return 0
  517. }
  518. // UintFlag is a flag with type uint
  519. type UintFlag struct {
  520. Name string
  521. Usage string
  522. EnvVar string
  523. FilePath string
  524. Hidden bool
  525. Value uint
  526. Destination *uint
  527. }
  528. // String returns a readable representation of this value
  529. // (for usage defaults)
  530. func (f UintFlag) String() string {
  531. return FlagStringer(f)
  532. }
  533. // GetName returns the name of the flag
  534. func (f UintFlag) GetName() string {
  535. return f.Name
  536. }
  537. // Uint looks up the value of a local UintFlag, returns
  538. // 0 if not found
  539. func (c *Context) Uint(name string) uint {
  540. return lookupUint(name, c.flagSet)
  541. }
  542. // GlobalUint looks up the value of a global UintFlag, returns
  543. // 0 if not found
  544. func (c *Context) GlobalUint(name string) uint {
  545. if fs := lookupGlobalFlagSet(name, c); fs != nil {
  546. return lookupUint(name, fs)
  547. }
  548. return 0
  549. }
  550. func lookupUint(name string, set *flag.FlagSet) uint {
  551. f := set.Lookup(name)
  552. if f != nil {
  553. parsed, err := strconv.ParseUint(f.Value.String(), 0, 64)
  554. if err != nil {
  555. return 0
  556. }
  557. return uint(parsed)
  558. }
  559. return 0
  560. }