Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1.61 KB

README.md

File metadata and controls

46 lines (36 loc) · 1.61 KB

Props

GoDoc Go Report Card Build Status

Command line flags made simple

Installation

go get -u github.com/libgolang/props

Usage

import (
  "fmt"
  "github.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")
  }
}

Why

  • 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

Features

  • 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().