-
Notifications
You must be signed in to change notification settings - Fork 122
cmd/loop: update urfave/cli to v3, auto-generate loop CLI reference manual and man file #1013
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dfb16df
cmd/loop: hide command forceautoloop
starius ea9f902
cmd/loop: parse --amt as int, not as string
starius e8f5a54
cmd/loop: parseAmt fails in negative amounts
starius 5fa5a4e
cmd/loop: parse start_time_ns as int, not string
starius dfad554
cmd/loop: parse string slice as string slice
starius 0ff9171
cmd/loop: fix validation of "static in --label"
starius 5e6e789
cmd/loop: urfave/cli -> urfave/cli/v3
starius 15f9423
cmd/loop: add commands "loop man", "loop markdown"
starius 8feab84
make: generate man and markdown files in docs/
starius 8ec28b2
ci: verify that documentation is up-to-date
starius 9eddee7
ci: run sqlc-check
starius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| _ "embed" | ||
| "fmt" | ||
|
|
||
| docs "github.com/urfave/cli-docs/v3" | ||
| "github.com/urfave/cli/v3" | ||
| ) | ||
|
|
||
| //go:embed markdown_tabular.md.gotmpl | ||
| var markdownTabularDocTemplate string | ||
|
|
||
| // We have a copy of this template taken from | ||
| // https://github.com/urfave/cli-docs where we remove column | ||
| // "Environment variables" if it has no values. | ||
| // TODO: remove this when https://github.com/urfave/cli-docs/pull/15 | ||
| // is merged. | ||
| func init() { | ||
| docs.MarkdownTabularDocTemplate = markdownTabularDocTemplate | ||
| } | ||
|
|
||
| var printManCommand = &cli.Command{ | ||
| Name: "man", | ||
| Usage: "prints man file", | ||
| Description: "Prints documentation of loop CLI in man format", | ||
| Action: printMan, | ||
| Hidden: true, | ||
| } | ||
|
|
||
| func printMan(_ context.Context, cmd *cli.Command) error { | ||
| root := filterNestedHelpCommands(cmd.Root()) | ||
|
|
||
| const userCommandsSection = 1 | ||
| man, err := docs.ToManWithSection(root, userCommandsSection) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to produce man: %w", err) | ||
| } | ||
|
|
||
| fmt.Println(man) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| var printMarkdownCommand = &cli.Command{ | ||
| Name: "markdown", | ||
| Usage: "prints markdown file", | ||
| Description: "Prints documentation of loop CLI in markdown format", | ||
| Action: printMarkdown, | ||
| Hidden: true, | ||
| } | ||
|
|
||
| func printMarkdown(_ context.Context, cmd *cli.Command) error { | ||
| root := filterNestedHelpCommands(cmd.Root()) | ||
|
|
||
| md, err := docs.ToTabularMarkdown(root, "loop") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to produce man: %w", err) | ||
| } | ||
|
|
||
| fmt.Println(md) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // filterNestedHelpCommands clones cmd, drops nested help commands, and normalises | ||
| // flag defaults so generated documentation avoids absolute paths. | ||
| func filterNestedHelpCommands(cmd *cli.Command) *cli.Command { | ||
| cloned := cloneCommand(cmd, 0) | ||
| overrideDocFlags(cloned) | ||
| return cloned | ||
| } | ||
|
|
||
| // cloneCommand clones the command, filtering out nested "help" subcommands. | ||
| func cloneCommand(cmd *cli.Command, depth int) *cli.Command { | ||
| if cmd == nil { | ||
| return nil | ||
| } | ||
|
|
||
| cloned := *cmd | ||
| if len(cmd.Commands) == 0 { | ||
| return &cloned | ||
| } | ||
|
|
||
| filtered := make([]*cli.Command, 0, len(cmd.Commands)) | ||
| for _, sub := range cmd.Commands { | ||
| if sub == nil { | ||
| continue | ||
| } | ||
| childDepth := depth + 1 | ||
|
|
||
| // TODO: remove when https://github.com/urfave/cli-docs/pull/16 | ||
| if childDepth > 0 && sub.Name == "help" { | ||
| continue | ||
| } | ||
|
|
||
| filtered = append(filtered, cloneCommand(sub, childDepth)) | ||
| } | ||
|
|
||
| cloned.Commands = filtered | ||
| return &cloned | ||
| } | ||
|
|
||
| // overrideDocFlags walks the command tree and replaces string flag defaults | ||
| // that leak user-specific filesystem paths, keeping generated docs stable. | ||
| func overrideDocFlags(cmd *cli.Command) { | ||
| if cmd == nil { | ||
| return | ||
| } | ||
|
|
||
| if len(cmd.Flags) > 0 { | ||
| clonedFlags := make([]cli.Flag, len(cmd.Flags)) | ||
| for i, fl := range cmd.Flags { | ||
| clonedFlags[i] = cloneFlagWithOverrides(fl) | ||
| } | ||
| cmd.Flags = clonedFlags | ||
| } | ||
|
|
||
| for _, sub := range cmd.Commands { | ||
| overrideDocFlags(sub) | ||
| } | ||
| } | ||
|
|
||
| // docFlagOverrides maps global flag names to the canonical values we want to | ||
| // show in documentation instead of user-specific absolute paths. | ||
| var docFlagOverrides = map[string]string{ | ||
| loopDirFlag.Name: "~/.loop", | ||
| tlsCertFlag.Name: "~/.loop/mainnet/tls.cert", | ||
| macaroonPathFlag.Name: "~/.loop/mainnet/loop.macaroon", | ||
| } | ||
|
|
||
| // cloneFlagWithOverrides returns a copy of flag with overridden default values | ||
| // when the flag participates in docFlagOverrides. Non-string flags are reused | ||
| // unchanged to minimise allocations. | ||
| func cloneFlagWithOverrides(flag cli.Flag) cli.Flag { | ||
| sf, ok := flag.(*cli.StringFlag) | ||
| if !ok { | ||
| return flag | ||
| } | ||
|
|
||
| value, ok := docFlagOverrides[sf.Name] | ||
| if !ok { | ||
| return flag | ||
| } | ||
|
|
||
| cloned := *sf | ||
| cloned.Value = value | ||
| cloned.DefaultText = value | ||
|
|
||
| return &cloned | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 command is already hidden behind the dev build flag, but nothing wrong with adding extra hidden flag.
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.
The man and the markdown are built using
loop-debugbinary built bymake build. That target builds with "dev" tag.