libgolang/props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDocGo Report CardBuild Status

Command line flags made simple

go get -u .com/libgolang/props
import (
  "fmt"
  ".com/libgolang/props"
)

func main() {
  if props.IsSet("name") {
    fmt.Printf("My Name is %s\n", props.GetProp("name"))
  } else {
    fmt.Printf("No name given\n")
  }
}
  • Does not require pre-defining properties. It dynamically figures out properties based on os.Args
  • Does no require 3rd party libraries
  • Just three functions GetProp, IsSet and GetArgs
  • Arguments with two dashes and an equal sign are interpreted as properties with a value. e.g.: --prop-name=value
  • Arguments with two dashes and NO equal sign will interpret the next argument as a value. If no argument is followed by the property, then it will have an empty value. e.g.: --prop-name value then GetProp("prop-name"): "value" and --prop-name --some-other-property then GetProp("prop-name"): ""
  • Arguments with one dash are interperted as Flags. If a value is passed to the flag it is igned and used as an argument in GetArgs(). e.g.: -p then IsSet("p") : true
  • Any argument not part of a flag or a property is added to the argument list and they can be retrived by calling GetArgs().

About

Configuration Made Simple

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published