main.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package flagparser
  2. import (
  3. "fmt"
  4. "io"
  5. "strings"
  6. )
  7. var data flagData
  8. func Help() bool {
  9. return data.Help()
  10. }
  11. func FprintUsage(writer io.Writer) (int, error) {
  12. return data.FprintUsage(writer)
  13. }
  14. func PrintUsage() (int, error) {
  15. return data.PrintUsage()
  16. }
  17. func FprintVersion(writer io.Writer) (int, error) {
  18. return data.FprintVersion(writer)
  19. }
  20. func PrintVersion() (int, error) {
  21. return data.PrintVersion()
  22. }
  23. func FprintLicense(writer io.Writer) (int, error) {
  24. return data.FprintLicense(writer)
  25. }
  26. func PrintLicense() (int, error) {
  27. return data.PrintLicense()
  28. }
  29. func FprintReport(writer io.Writer) (int, error) {
  30. return data.FprintReport(writer)
  31. }
  32. func PrintReport() (int, error) {
  33. return data.PrintReport()
  34. }
  35. func FprintLF(writer io.Writer) (int, error) {
  36. return data.FprintLF(writer)
  37. }
  38. func PrintLF() (int, error) {
  39. return data.PrintLF()
  40. }
  41. func Version() bool {
  42. return data.Version()
  43. }
  44. func License() bool {
  45. return data.License()
  46. }
  47. func Report() bool {
  48. return data.Report()
  49. }
  50. func NotRunMode() bool {
  51. return Help() || Version() || License() || Report()
  52. }
  53. func NotRunModeOption() string {
  54. if !NotRunMode() {
  55. return ""
  56. }
  57. var result strings.Builder
  58. if data.Help() {
  59. result.WriteString(fmt.Sprintf("%s%s, ", OptionPrefix, data.HelpName))
  60. }
  61. if data.Version() {
  62. result.WriteString(fmt.Sprintf("%s%s, ", OptionPrefix, data.VersionName))
  63. }
  64. if data.License() {
  65. result.WriteString(fmt.Sprintf("%s%s, ", OptionPrefix, data.LicenseName))
  66. }
  67. if data.Report() {
  68. result.WriteString(fmt.Sprintf("%s%s, ", OptionPrefix, data.ReportName))
  69. }
  70. return strings.TrimSuffix(result.String(), ", ")
  71. }
  72. func ConfigFile() string {
  73. return data.ConfigFile()
  74. }
  75. func NotRunAutoReload() bool {
  76. return data.NotAutoReloadData
  77. }
  78. func RunAutoReload() bool {
  79. return !NotRunAutoReload()
  80. }
  81. func SetOutput(writer io.Writer) {
  82. data.SetOutput(writer)
  83. }