The standard library flag and cobra

main Package 
Import "In Flag" 

var BOOL B 
var BOOL * Q 
FUNC the init () { 

	var BOOL B 
	// embodiment a flag.Type () * Type Type stringint the Duration can BOOL 
	Q = flag.Bool ( "Q", to false, "the new binding, the return address pointing to a bool") 

	// embodiment 2 flag.TypeVar binding 
	flag.BoolVar (& b, "b" , false, " binding mode 2") 


} 
FUNC main () { 
	/ / () command is parsed by the parse 
	flag.Parse () 
	the println (Q *, B) 
}

 Projects generally recommend the use of cobra

Chinese translation of the document https://www.jianshu.com/p/7abe7cff5384

Official documents https://github.com/spf13/cobra/blob/master/cobra/README.md

 

Guess you like

Origin www.cnblogs.com/thotf/p/11918713.html