Skip to content

Commit

Permalink
Merge pull request urfave#1800 from urfave/v2-maint-goimports
Browse files Browse the repository at this point in the history
Helper messages for documenting build process
  • Loading branch information
abitrolly authored Jul 23, 2023
2 parents 041303a + 648b8c6 commit b686f4f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.*envrc
.envrc
.idea
# goimports is installed here if not available
/.local/
/site/
coverage.txt
Expand Down
59 changes: 30 additions & 29 deletions cmd/urfave-cli-genflags/generated.gotmpl
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
// WARNING: this file is generated. DO NOT EDIT
{{.HeaderWarning}}

package {{.PackageName}}

{{range .SortedFlagTypes}}
{{range .SortedFlagTypes -}}
// {{.TypeName}} is a flag with type {{if .ValuePointer}}*{{end}}{{.GoType}}
type {{.TypeName}} struct {
Name string
Name string

Category string
DefaultText string
FilePath string
Usage string
Category string
DefaultText string
FilePath string
Usage string

Required bool
Hidden bool
HasBeenSet bool
Required bool
Hidden bool
HasBeenSet bool

Value {{if .ValuePointer}}*{{end}}{{.GoType}}
Destination {{if .NoDestinationPointer}}{{else}}*{{end}}{{.GoType}}
Value {{if .ValuePointer}}*{{end}}{{.GoType}}
Destination {{if .NoDestinationPointer}}{{else}}*{{end}}{{.GoType}}

Aliases []string
EnvVars []string
Aliases []string
EnvVars []string

defaultValue {{if .ValuePointer}}*{{end}}{{.GoType}}

{{range .StructFields}}
{{.Name}} {{if .Pointer}}*{{end}}{{.Type}}
{{end}}
defaultValue {{if .ValuePointer}}*{{end}}{{.GoType}}
{{ range .StructFields}}
{{.Name}} {{if .Pointer}}*{{end}}{{.Type}}
{{end -}}
}

{{if .GenerateFmtStringerInterface}}
{{if .GenerateFmtStringerInterface -}}
// String returns a readable representation of this value (for usage defaults)
func (f *{{.TypeName}}) String() string {
return {{$.UrfaveCLINamespace}}FlagStringer(f)
return {{$.UrfaveCLINamespace}}FlagStringer(f)
}

{{end}}{{/* /if .GenerateFmtStringerInterface */}}

{{if .GenerateFlagInterface}}
{{- if .GenerateFlagInterface -}}
// IsSet returns whether or not the flag has been set through env or file
func (f *{{.TypeName}}) IsSet() bool {
return f.HasBeenSet
return f.HasBeenSet
}

// Names returns the names of the flag
func (f *{{.TypeName}}) Names() []string {
return {{$.UrfaveCLINamespace}}FlagNames(f.Name, f.Aliases)
return {{$.UrfaveCLINamespace}}FlagNames(f.Name, f.Aliases)
}

{{end}}{{/* /if .GenerateFlagInterface */}}

{{if .GenerateRequiredFlagInterface}}
{{- if .GenerateRequiredFlagInterface -}}
// IsRequired returns whether or not the flag is required
func (f *{{.TypeName}}) IsRequired() bool {
return f.Required
return f.Required
}

{{end}}{{/* /if .GenerateRequiredFlagInterface */}}

{{if .GenerateVisibleFlagInterface}}
{{- if .GenerateVisibleFlagInterface -}}
// IsVisible returns true if the flag is not hidden, otherwise false
func (f *{{.TypeName}}) IsVisible() bool {
return !f.Hidden
}
{{end}}{{/* /if .GenerateVisibleFlagInterface */}}
{{end}}{{/* /range .SortedFlagTypes */}}

// vim{{/* 👻 */}}:ro
{{/*
{{- "// vim"}}:ro
{{- /* 👻
vim:filetype=gotexttmpl
*/}}
4 changes: 4 additions & 0 deletions cmd/urfave-cli-genflags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ type Spec struct {
UrfaveCLITestNamespace string `yaml:"urfave_cli_test_namespace"`
}

func (Spec) HeaderWarning() string {
return "// WARNING: this file is generated. DO NOT EDIT"
}

func (gfs *Spec) SortedFlagTypes() []*FlagType {
typeNames := []string{}

Expand Down
3 changes: 3 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func main() {
{
Name: "generate",
Action: GenerateActionFunc,
Usage: "generate API docs",
},
{
Name: "yamlfmt",
Expand Down Expand Up @@ -496,6 +497,7 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) {
func GenerateActionFunc(cCtx *cli.Context) error {
top := cCtx.Path("top")

log.Println("--- generating godoc-current.txt API reference ---")
cliDocs, err := sh("go", "doc", "-all", top)
if err != nil {
return err
Expand All @@ -514,6 +516,7 @@ func GenerateActionFunc(cCtx *cli.Context) error {
return err
}

log.Println("--- generating Go source files ---")
return runCmd("go", "generate", cCtx.Path("top")+"/...")
}

Expand Down

0 comments on commit b686f4f

Please sign in to comment.