gexe icon indicating copy to clipboard operation
gexe copied to clipboard

Accessing program flags

Open vladimirvivien opened this issue 4 years ago • 0 comments

Echo should provide easy access to program flags. As an echo user, I should be able to access flags using something similar to the following:

e := echo.New()
if e.Flags("flagname").AsBool() {
    fmt.Println("flag found")
}

echo should provide access to program argments via member Flags as echo.Echo.Flags:

  • Flags.Arg(index int) string
  • Flags.Args() []string all passed raw arguments

Method Flags.Get returns a value of type echo.Flag which represents a processed flag value:

  • Flags.Get("flagname") *echo.Flag

Type echo.Flag should provide utility methods to access the flag values

  • Flag.AsString("name") string
  • Flag.AsBool("flagname") bool
  • Flag.AsInt64("flagname") int64
  • Flag.AsFloat64("flagname") float64
  • Flag.Err() last produced error during flag processing
  • Etc

Method Flags.Add should be u sed to define a new flag:

  • Flags.Add(name, default, usage string) *Flags

vladimirvivien avatar May 25 '20 21:05 vladimirvivien