fmt.Fprint(os.Stdout," ↳ checking long description\n")
cmdPath:=cmd.CommandPath()
long:=cmd.Long
iflen(long)>0{
ifstrings.Trim(long," \t\n")!=long{
return[]error{fmt.Errorf(`command %q: long description is not normalized
↳ make sure you are calling templates.LongDesc (from pkg/cmd/templates) before assigning cmd.Long`,cmdPath)}
return[]error{fmt.Errorf(`command %q: long description is not normalized, make sure you are calling templates.LongDesc (from pkg/cmd/templates) before assigning cmd.Long`,cmdPath)}
}
}
returnnil
}
funcCheckExamples(cmd*cobra.Command)[]error{
fmt.Fprint(os.Stdout," ↳ checking examples\n")
cmdPath:=cmd.CommandPath()
examples:=cmd.Example
errors:=[]error{}
iflen(examples)>0{
for_,line:=rangestrings.Split(examples,"\n"){
if!strings.HasPrefix(line,templates.Indentation){
errors=append(errors,fmt.Errorf(`command %q: examples are not normalized
↳ make sure you are calling templates.Examples (from pkg/cmd/templates) before assigning cmd.Example`,cmdPath))
errors=append(errors,fmt.Errorf(`command %q: examples are not normalized, make sure you are calling templates.Examples (from pkg/cmd/templates) before assigning cmd.Example`,cmdPath))
errors=append(errors,fmt.Errorf("command %q: unable to compile regex to check flags",cmd.CommandPath()))
returnerrors
}
for_,flag:=rangeallFlagsSlice{
name:=flag.Name
if!regex.MatchString(name){
errors=append(errors,fmt.Errorf("command %q: flag name %q is invalid, long form of flag names can only contain lowercase characters or dash (must match %v)",cmd.CommandPath(),name,regex))
}
}
returnerrors
}
funcCheckGlobalVarFlags()[]error{
fmt.Fprint(os.Stdout," ↳ checking flags from global vars\n")
errors:=[]error{}
pflag.CommandLine.VisitAll(func(f*pflag.Flag){
errors=append(errors,fmt.Errorf("flag %q is invalid, please don't register any flag under the global variable \"CommandLine\"",f.Name))