Standard library / flag

flag.FlagSet.Int()

Registers a flag on an independent FlagSet. Signed machine-width integer; accepts decimal, hexadecimal and other supported integer literal forms. Run with arguments: ["-x=7"]. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func (f *FlagSet) Int(name string, value int, usage string) *int

Parameters & Attributes

NameTypeDescription
namestringName of the flag or flag set.
valueintDefault value for registration, or text to parse for Set.
usagestringHelp text describing the flag.

Return Value

*int

Registers a flag on an independent FlagSet.

Working Example

Example Snippetgo
package main
import (  "flag"  "fmt"  "os")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  f := flag.NewFlagSet("demo", flag.ContinueOnError)  v := f.Int("x", 3, "value")  check(f.Parse(os.Args[1:]))  fmt.Println(*v)}
Go Reference