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) *intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name of the flag or flag set. |
| value | int | Default value for registration, or text to parse for Set. |
| usage | string | Help 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)}