diff --git a/provider/arg/dump.go b/provider/arg/dump.go index ff6dc77..a27be9d 100644 --- a/provider/arg/dump.go +++ b/provider/arg/dump.go @@ -31,6 +31,16 @@ func ResolveStyle(params param.Params) ViewStyle { return vs } +func WithStyle(comment, info Style) param.Option { + return func(p param.Params) param.Params { + return param.With(p, paramDumpReferenceView, ViewStyle{ + Comment: comment, + Info: info, + MLen: 0, + }) + } +} + type ViewStyle struct { Comment Style Info Style @@ -87,14 +97,18 @@ func (d Dump) keyMaxLen(views ...View) int { var maxLen int for _, vi := range views { - vlen := len(vi.Name(d.sep)) + 6 + vlen := len(vi.Name(d.sep)) + d.space - if !vi.IsBool() { - vlen = vlen*2 + 1 - } + if !vi.IsArgument() { + if !vi.IsBool() { + vlen = vlen*2 + 1 + } - if def := vi.Default(); def != "" { - vlen += 2 + if def := vi.Default(); def != "" { + vlen += d.space + } + + vlen += 4 + d.space } if vlen > maxLen { @@ -300,7 +314,7 @@ func (v Views) Options() []View { } sort.Slice(opts, func(i, j int) bool { - return opts[i].Name(dash) < opts[j].Name(dash) + return opts[i].Pos() < opts[j].Pos() }) return opts @@ -314,6 +328,10 @@ func NewView(params config.Option, parent *View) View { keys = append(keys, parent.Keys()...) } + if !ok { + pos = param.Position(params) + } + if name := params.Name(); name != "" { keys = append(keys, name) } diff --git a/provider/arg/dump_test.go b/provider/arg/dump_test.go index 11aeb38..d123cc6 100644 --- a/provider/arg/dump_test.go +++ b/provider/arg/dump_test.go @@ -14,17 +14,17 @@ func TestDumpReference(t *testing.T) { //nolint:dupword const expect = ` Arguments: - config config [default:config.hcl] - user-name username + config config [default:config.hcl] + user-name username Options: - --end-after[=END-AFTER] after (multiple values allowed) - --end-{service}-after[=END-{SERVICE}-AFTER] after - -l, --listen[=LISTEN] listen [default:8080] - --start-at[=START-AT] start at [default:2010-01-02T15:04:05Z] - -t, --timeout[=TIMEOUT] timeout (multiple values allowed) - -u, --url[=URL] url (multiple values allowed) - -p, --user-password[=USER-PASSWORD] user pass + -l, --listen[=LISTEN] listen [default:8080] + -p, --user-password[=USER-PASSWORD] user pass + -u, --url[=URL] url (multiple values allowed) + -t, --timeout[=TIMEOUT] timeout (multiple values allowed) + --start-at[=START-AT] start at [default:2010-01-02T15:04:05Z] + --end-after[=END-AFTER] after (multiple values allowed) + --end-{service}-after[=END-{SERVICE}-AFTER] after ` dump := arg.NewDump()