flags

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntRange

type IntRange struct {
	Value, Min, Max int
}

IntRange is used to specify an *inclusive* range for the std "flag" package. The result is stored in Value.

Example
package main

import (
	"flag"
	"fmt"

	"github.com/aod/elver/flags"
)

func main() {
	fs := flag.NewFlagSet("example usage of IntRange", flag.ContinueOnError)

	ir := flags.IntRange{Min: 0, Max: 10}
	fs.Var(&ir, "num", "select a number between 1 to 10")

	fs.Parse([]string{"-num", "6"})

	fmt.Println(ir.Value)
}
Output:

6

func (*IntRange) Set

func (ir *IntRange) Set(v string) error

Set satasfies part of the flag.Value interface. It returns an error if Atoi of v failes or num resides outside of the inclusive int range. Otherwise the result is stored in Value.

func (*IntRange) String

func (ir *IntRange) String() string

Jump to

Keyboard shortcuts

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