Skip to content

Conversation

@dfinkel
Copy link
Contributor

@dfinkel dfinkel commented Jun 10, 2025

It's time to get panels out of an experimental branch and merge it into the main tree.
It's been languishing with only a few broken tests for a while.

For now, it only supports one level of subcommand, but that's enough for an MVP.
There are two example tools in this PR which should elucidate how to use this package.
(we should add some example tests later)

Sachi Nagada and others added 17 commits February 26, 2025 14:22
* add Must() wrapper for registering subcommands

* add complex binary with panel constructor
Still only supports one level of subcommands (that's now more difficult
than simple recursion, since the config-type for each layer is likely to
be different)
Fix a couple lint nags due to capitalization of error-strings, and fix
error-wrapping in a few places.
The stdlib flag package has a convenient ErrHelp type. Use that as a
sentinel to short-circuit error-handling.
Consolidate the help handling a bit and make it possible for users to
trigger usage printing.

By moving all the usage-generation/printing into panels.help(), we get
some nice consistency, and access to parent subcommands (including their
flags)

This now includes the root-level flags in addition to the specific
subcommand requested, whether it's called as `binary help subcmd` or
`binary subcmd --help`

The new sentinel errors let us dump usage hints when there's a problem
parsing in a subcommand (without having to figure out how to traverse
back up the chain).
Tests now build & pass.

Due to the constraints of table generics, we had to pull the table test
loop body into its own generic function.
A lot of cases don't need to do anything with the argument-list to
construct the help text, and can provide static strings.

Simplify that use-case by providing an embeddable implementation that
they can set string-values on.
Rather than passing an argument to NewDials that's just a FlagSource,
pass a struct, so we can pass additional info as the system evolves.
Clarify some comments and rename a varialbe to make the code easier to
follow.
Also, add a stub package description.
It's not worth keeping compatibility with old versions indefinitely,
just bump to 1.23 so we get slices.Sorted and maps.Keys.
Copy link
Contributor

@sergiosalvatore sergiosalvatore left a comment

Choose a reason for hiding this comment

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

A couple minor nits...

}

func indentString(s string) string {
return "\t" + strings.ReplaceAll(s, "\n", "\t\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want this to be:

Suggested change
return "\t" + strings.ReplaceAll(s, "\n", "\t\n")
return "\t" + strings.ReplaceAll(s, "\n", "\n\t")

}

s := p.helpString("fazzle")
t.Logf("%s", s)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably have a simple assertion in here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants