flags

package
v0.0.0-...-e0aed8b Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package flags extends the standard flag package.

Example
package main

import (
	"flag"
	"fmt"
	"os"

	"github.com/Akagi201/utilgo/flags"
)

var (
	tags       flags.Array
	attributes flags.Map
)

func init() {
	flag.Var(&tags, "tag", "Tag to add.")
	flag.Var(&attributes, "attribute", "Attribute to add.")
}

func main() {
	os.Args = []string{"-tag=1", "-tag=2", "-attribute", "foo:bar", "-attribute", "baz:boo"}
	flag.Parse()

	fmt.Println("tags provided:", tags)
	fmt.Println("attributes provided:", attributes)

	// When started with:
	// -tag=1 -tag=2 -attribute foo:bar -attribute baz:boo
	// Outputs:
	// tags provided: [1 2]
	// attributes provided: map[foo:bar baz:boo]
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array []string

Array represents string array flag variable.

func (*Array) Set

func (a *Array) Set(value string) error

Set appends element to the array.

func (*Array) String

func (a *Array) String() string

String returns the string representation of the array.

type Map

type Map map[string]string

Map represents map[string]string flag variable.

func (*Map) Set

func (m *Map) Set(value string) error

Set adds element to the map. It must be in key:value format, otherwise error is returned.

func (*Map) String

func (m *Map) String() string

String returns the string representation of the map.

Jump to

Keyboard shortcuts

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