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

cmd/geth, internal/flags, go.mod: colorize cli help, support env vars #28103

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

karalabe
Copy link
Member

This PR does three things:

  • Updates the CLI dependency (because why not)
  • Extends each CLI flag with an auto-generated env var that can be used for the same purpose. This should help initialize Geth in cloud and other container infrastructure which are more tuned to being inited via env vars vs flags or config files.
  • Updates the --help screen to use colored flag and category names.
Screenshot 2023-09-13 at 14 15 36

@karalabe karalabe added this to the 1.13.1 milestone Sep 13, 2023

case *DirectoryFlag:
flag.EnvVars = append(flag.EnvVars, envvar)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super ugly, good luck making it nicer :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will become much easier with cli.v3 I think, because it uses generics to define the flag types.

Copy link
Contributor

@fjl fjl Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could always use reflect here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh :) Not worth the complexity for fixing 20 lines of code.


// Annotate flag categories with colors (private template, so need to
// copy-paste the entire thing here...)
cli.AppHelpTemplate = strings.ReplaceAll(cli.AppHelpTemplate, "{{template \"visibleFlagCategoryTemplate\" .}}", "{{range .VisibleFlagCategories}}\n {{if .Name}}\u001B[33m{{.Name}}\u001B[0m\n\n {{end}}{{$flglen := len .Flags}}{{range $i, $e := .Flags}}{{if eq (subtract $flglen $i) 1}}{{$e}}\n{{else}}{{$e}}\n {{end}}{{end}}{{end}}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so I explictly tried to avoid overriding the help templates to make future updates of the library easier. They keep adding stuff upstream and it's good not to have it custom.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but they made teh damn subtemplate private.

@holiman
Copy link
Contributor

holiman commented Sep 14, 2023

geth -h | less mangles the output, but geth -h | more works perfectly (as in: color not stripped, not mangled, but still there), and also e.g. geth -h | grep cache works perfectly

@holiman
Copy link
Contributor

holiman commented Sep 14, 2023

Random observation, re priority order

$ GETH_MINE=1 geth
...
ERROR[09-14|08:56:16.870] Cannot start mining without etherbase    err="etherbase must be explicitly specified"
Fatal: Failed to start mining: etherbase missing: etherbase must be explicitly specified
$ GETH_MINE=1 geth --mine=false
... works fine..

👍

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman
Copy link
Contributor

holiman commented Sep 14, 2023

With the latest change

geth -h | less, geth -h | more and geth -h | grep cache all works identically: neither mangles the output, but color is stripped in all cases.

@karalabe karalabe merged commit d9fbb71 into ethereum:master Sep 14, 2023
1 of 2 checks passed
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
…ethereum#28103)

* cmd/geth, internal/flags, go.mod: colorize cli help, support env vars

* internal/flags: use stdout, not stderr for terminal detection
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants