You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

628 lines
14 KiB

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