Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper messages for documenting build process #1800

Merged
merged 4 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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