-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(docs): generate cli docs directly from the struct #12717
base: master
Are you sure you want to change the base?
feat(docs): generate cli docs directly from the struct #12717
Conversation
@@ -1,380 +0,0 @@ | |||
[API] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're going to need to replicate this too, but it should be pretty easy, the lotus config default
is fairly simple:
Lines 32 to 40 in 07f2f69
c := config.DefaultFullNode() | |
cb, err := config.ConfigUpdate(c, nil, config.Commented(!cctx.Bool("no-comment")), config.DefaultKeepUncommented()) | |
if err != nil { | |
return err | |
} | |
fmt.Println(string(cb)) | |
|
||
### lotus-miner log alerts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did this one come out of order? do you know why urfave puts it here but yours doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I get why this is shuffled now -- the original is following the order as they appear in the COMMANDS:
output, but yours is following the naive order they appear in the Commands
slice. I think we should follow that same order—either retain it when you print COMMANDS:
or just follow this algorithm:
- Iterate over the
Commands
slice and print out any that don't have aCategory
- Iterate over the
Commands
slice again and print out any that do have aCategory
I don't know if there's a sorting on Category
name applied, maybe it won't matter for now.
Looks like a lot of the logic for this lives in https://github.com/urfave/cli/blob/main/help.go and the templates in here (unfortunately not exported!) are here: https://github.com/urfave/cli/blob/main/template.go Use this as an exercise in minimising the diff, that's your challenge - how can you get to near zero red/green lines in the diff here for the documentation output, aiming to only make changes where the existing script is getting it wrong (mostly missing some things I believe). |
1f2c2c4
to
f616568
Compare
@akaladarshi : I assume you'll re-request review when you're ready for it to be looked at again. |
documentation/en/cli-lotus-miner.md
Outdated
--miner-repo value, --storagerepo Specify miner repo path. flag(storagerepo) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON (default: "~/.lotusminer") [LOTUS_MINER_PATH, LOTUS_STORAGE_PATH] | ||
--vv enables very verbose mode, useful for debugging the CLI (default: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--storagerepo
should be --storagerepo value
? and then the spacing for this longest line should be the same as the others
documentation/en/cli-lotus.md
Outdated
help, h Shows a list of commands or help for one command | ||
daemon Start a lotus daemon process |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have a minimum width setting here that needs adjusting? looks like we have 4 extra spaces than we need
documentation/en/cli-lotus-miner.md
Outdated
--version, -v print the version | ||
--actor value, -a specify other actor to query / manipulate | ||
--color use color in display output (default: depends on output being a TTY) | ||
--panic-reports value (default: "~/.lotusminer") [LOTUS_PANIC_REPORT_PATH] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, this one is missing because Hidden: true
- better build that into your code too, if a flag is Hidden
, then exclude it from the list
func PprofCmd() *cli.Command { | ||
return &cli.Command{ | ||
Name: "pprof", | ||
Hidden: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to obey this so it doesn't show up in docs, same as flags, check for Hidden
and skip if true
documentation/en/cli-lotus.md
Outdated
@@ -1114,7 +1178,23 @@ OPTIONS: | |||
--help, -h show help | |||
``` | |||
|
|||
### lotus mpool clear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is new because it's Hidden
- because it's both deprecated and pretty unsafe to invoke so we don't want to encourage it
Very close @akaladarshi, good work so far. I haven't done an in-depth review of the actual code, I'm mainly looking at the output and assuming that the code is good, I'll look over that next. |
@@ -13,19 +13,19 @@ var Commands = []*cli.Command{ | |||
lcli.WithCategory("basic", lcli.MultisigCmd), | |||
lcli.WithCategory("basic", lcli.FilplusCmd), | |||
lcli.WithCategory("basic", lcli.PaychCmd), | |||
lcli.WithCategory("developer", lcli.AuthCmd), | |||
lcli.WithCategory("developer", lcli.AuthCmd()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do these need to become functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, lotus
and lotus-miner
shared global command variables, causing conflicts when running app.Run("lotus-miner", "-h")
. This led to jumbled help output like lotus-miner lotus auth
.
|
||
var formatted string | ||
if value != "" { | ||
formatted = fmt.Sprintf(" %-30s %s (default: %s)", names, usage, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatted = fmt.Sprintf(" %-30s %s (default: %s)", names, usage, value) | |
defpfx := " " | |
if usage == "" { | |
defpfx = "" | |
} | |
formatted = fmt.Sprintf(" %-30s %s%s(default: %s)", names, usage, defpfx, value) |
something like this would deal with the case where there's no usage string; alternatively you could extend usage
by one space if it's not ""
.
I'm not sure this is strictly needed when you account for the Hidden
flags but it would fix current alignment problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this -30
is getting in the way when the names
is too long. Like when --miner-repo value, --storagerepo
comes in to play which is longer than you want.
Here's what I think I'd do given your current code structure so as not to have to make too many changes: make the this number a property of FlagFormatter
that you pass in when you construct it (or make a default value you can override if you like) (you'll probably need to fmt.Sprintf
the format itself to insert it). Then you do two passes iterating through your flags - the first pass looks at the maximum length of the names
from GetData
and then the second pass sets the maximum length if it's greater than 30 and does the actual print.
@rvagg I think I found a minimum solution for this we can directly use the urface cli package for generating, Initially I though we need to print everything (hidden), but this will directly print the correct format value. customAppData := func() map[string]interface{} {
return map[string]interface{}{
"ExtraInfo": g.app.ExtraInfo,
}
}
cli.HelpPrinterCustom(header, cli.AppHelpTemplate, g.app, customAppData()) |
Removed the above change in favour of |
Related Issues
Fixes: #12706