packagemainimport("fmt""strings""github.com/spf13/cobra")funcmain(){varechoTimesintvarcmdPrint=&cobra.Command{Use:"print [string to print]",Short:"Print anything to the screen",Long:`printisforprintinganythingbacktothescreen.Formanyyearspeoplehaveprintedbacktothescreen.`,Args:cobra.MinimumNArgs(1),Run:func(cmd*cobra.Command,args[]string){fmt.Println("Print: "+strings.Join(args," "))},}varcmdEcho=&cobra.Command{Use:"echo [string to echo]",Short:"Echo anything to the screen",Long:`echoisforechoinganythingback.Echoworksalotlikeprint,exceptithasachildcommand.`,Args:cobra.MinimumNArgs(1),Run:func(cmd*cobra.Command,args[]string){fmt.Println("Print: "+strings.Join(args," "))},}varcmdTimes=&cobra.Command{Use:"times [# times] [string to echo]",Short:"Echo anything to the screen more times",Long:`echothingsmultipletimesbacktotheuserbyprovidingacountandastring.`,Args:cobra.MinimumNArgs(1),Run:func(cmd*cobra.Command,args[]string){fori:=0;i<echoTimes;i++{fmt.Println("Echo: "+strings.Join(args," "))}},}cmdTimes.Flags().IntVarP(&echoTimes,"times","t",1,"times to echo the input")varrootCmd=&cobra.Command{Use:"app"}rootCmd.AddCommand(cmdPrint,cmdEcho)cmdEcho.AddCommand(cmdTimes)rootCmd.Execute()}
[root@iZbp18sfxy8ixd9t5vscnaZ~]# gitusage:git[--version][--help][-cname=value][--exec-path[=<path>]][--html-path][--man-path][--info-path][-p|--paginate|--no-pager][--no-replace-objects][--bare][--git-dir=<path>][--work-tree=<path>][--namespace=<name>]<command>[<args>]Themostcommonlyusedgitcommandsare:addAddfilecontentstotheindexbisectFindbybinarysearchthechangethatintroducedabugbranchList,create,ordeletebranchescheckoutCheckoutabranchorpathstotheworkingtreecloneClonearepositoryintoanewdirectorycommitRecordchangestotherepositorydiffShowchangesbetweencommits,commitandworkingtree,etcfetchDownloadobjectsandrefsfromanotherrepositorygrepPrintlinesmatchingapatterninitCreateanemptyGitrepositoryorreinitializeanexistingonelogShowcommitlogsmergeJointwoormoredevelopmenthistoriestogethermvMoveorrenameafile,adirectory,orasymlinkpullFetchfromandmergewithanotherrepositoryoralocalbranchpushUpdateremoterefsalongwithassociatedobjectsrebaseForward-portlocalcommitstotheupdatedupstreamheadresetResetcurrentHEADtothespecifiedstatermRemovefilesfromtheworkingtreeandfromtheindexshowShowvarioustypesofobjectsstatusShowtheworkingtreestatustagCreate,list,deleteorverifyatagobjectsignedwithGPG'git help -a'and'git help -g'listsavailablesubcommandsandsomeconceptguides.See'git help <command>'or'git help <concept>'toreadaboutaspecificsubcommandorconcept.