Golang flag.Flag type example

package flag

A Flag represents the state of a flag.

 type Flag struct {
 Name string // name as it appears on command line
 Usage string // help message
 Value Value  // value as set
 DefValue string // default value (as text); for usage message
 }

Golang flag.Flag type usage example

 package main

 import (
 "flag"
 "fmt"
 )

 func main() {

 verbose := flag.String("verbose", "on", "Turn verbose mode on or off.")
 flag.Parse()

 fmt.Println(flag.Lookup("verbose")) // print the Flag struct

 }

Output :

&{verbose Turn verbose mode on or off. on on}

Break down to :

Name = verbose

Usage = Turn verbose mode on or off

Value = on

DefValue = on

Reference :

http://golang.org/pkg/flag/#Flag

Advertisement