Help us shape the future of Go! Take the 2026 Go Developer Survey

props

package module
v1.2.363 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 3 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetArgs

func GetArgs() []string

GetArgs regurns any argument that is not a property name, flag or property value

func GetProp

func GetProp(name string) string

GetProp returns the value of a property, if not set it returns an empty string

func IsSet

func IsSet(name string) bool

IsSet returns true if property is set, otherwise it returns false

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL