Merge pull request 'add atr dump style' (#42) from style into master
All checks were successful
Go Action / goaction (push) Successful in 1m1s

Reviewed-on: #42
This commit was merged in pull request #42.
This commit is contained in:
2026-01-04 22:18:30 +03:00
2 changed files with 34 additions and 16 deletions

View File

@@ -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)
}

View File

@@ -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()