From c54dfd004998d535ccc6589200b7c42705120ff4 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 22 Jul 2023 16:19:22 +0300 Subject: [PATCH 1/4] Helper messages for documenting build process I don't have `goimport` installed, and running `make` as described in https://cli.urfave.org/CONTRIBUTING/#development-workflow fails. Took this opportunity to enhance the process a bit. I see that `zz_generated.flags.go` is invalid without `goimports` (for whatever reason it is needed). And I need to check why `goimports` is not installed into `./.local/bin` automatically. --- .gitignore | 1 + internal/build/build.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index d7d26b1fca..1ef91a60be 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .*envrc .envrc .idea +# goimports is installed here if not available /.local/ /site/ coverage.txt diff --git a/internal/build/build.go b/internal/build/build.go index 00dc5f741e..490edb3faa 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -82,6 +82,7 @@ func main() { { Name: "generate", Action: GenerateActionFunc, + Usage: "generate API docs", }, { Name: "yamlfmt", @@ -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 @@ -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")+"/...") } From fe5a43d1c4c0e9905d0cf1b0b12c4951517180ba Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 22 Jul 2023 17:31:05 +0300 Subject: [PATCH 2/4] Clarify what is generated and what is not --- cmd/urfave-cli-genflags/generated.gotmpl | 2 +- cmd/urfave-cli-genflags/main.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/urfave-cli-genflags/generated.gotmpl b/cmd/urfave-cli-genflags/generated.gotmpl index 3720e6a1b8..60e0c3a142 100644 --- a/cmd/urfave-cli-genflags/generated.gotmpl +++ b/cmd/urfave-cli-genflags/generated.gotmpl @@ -1,4 +1,4 @@ -// WARNING: this file is generated. DO NOT EDIT +{{.HeaderWarning}} package {{.PackageName}} diff --git a/cmd/urfave-cli-genflags/main.go b/cmd/urfave-cli-genflags/main.go index 240b5977b0..c94c564244 100644 --- a/cmd/urfave-cli-genflags/main.go +++ b/cmd/urfave-cli-genflags/main.go @@ -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{} From 4d1267c1a8e9897a6998840736733b58ad160fb5 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 22 Jul 2023 17:47:30 +0300 Subject: [PATCH 3/4] Fix template indentation without `goimports` --- cmd/urfave-cli-genflags/generated.gotmpl | 40 ++++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/urfave-cli-genflags/generated.gotmpl b/cmd/urfave-cli-genflags/generated.gotmpl index 60e0c3a142..49871b2376 100644 --- a/cmd/urfave-cli-genflags/generated.gotmpl +++ b/cmd/urfave-cli-genflags/generated.gotmpl @@ -5,46 +5,46 @@ package {{.PackageName}} {{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}} + defaultValue {{if .ValuePointer}}*{{end}}{{.GoType}} - {{range .StructFields}} - {{.Name}} {{if .Pointer}}*{{end}}{{.Type}} - {{end}} + {{range .StructFields}} + {{.Name}} {{if .Pointer}}*{{end}}{{.Type}} + {{end}} } {{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}} // 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 */}} @@ -52,7 +52,7 @@ func (f *{{.TypeName}}) Names() []string { {{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 */}} From 648b8c6c23c416c4d872f77a62aa6d910b3ee2a3 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 22 Jul 2023 18:24:16 +0300 Subject: [PATCH 4/4] Fix generator whitespaces --- cmd/urfave-cli-genflags/generated.gotmpl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/urfave-cli-genflags/generated.gotmpl b/cmd/urfave-cli-genflags/generated.gotmpl index 49871b2376..dfa5e3c4f0 100644 --- a/cmd/urfave-cli-genflags/generated.gotmpl +++ b/cmd/urfave-cli-genflags/generated.gotmpl @@ -2,7 +2,7 @@ package {{.PackageName}} -{{range .SortedFlagTypes}} +{{range .SortedFlagTypes -}} // {{.TypeName}} is a flag with type {{if .ValuePointer}}*{{end}}{{.GoType}} type {{.TypeName}} struct { Name string @@ -23,20 +23,20 @@ type {{.TypeName}} struct { EnvVars []string defaultValue {{if .ValuePointer}}*{{end}}{{.GoType}} - - {{range .StructFields}} +{{ range .StructFields}} {{.Name}} {{if .Pointer}}*{{end}}{{.Type}} - {{end}} +{{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) } + {{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 @@ -49,14 +49,15 @@ func (f *{{.TypeName}}) Names() []string { {{end}}{{/* /if .GenerateFlagInterface */}} -{{if .GenerateRequiredFlagInterface}} +{{- if .GenerateRequiredFlagInterface -}} // IsRequired returns whether or not the flag is required func (f *{{.TypeName}}) IsRequired() bool { 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 @@ -64,7 +65,7 @@ func (f *{{.TypeName}}) IsVisible() bool { {{end}}{{/* /if .GenerateVisibleFlagInterface */}} {{end}}{{/* /range .SortedFlagTypes */}} -// vim{{/* 👻 */}}:ro -{{/* +{{- "// vim"}}:ro +{{- /* 👻 vim:filetype=gotexttmpl */}}