Skip to content

Commit

Permalink
fix/improve help-screen: header, footer, desc, examples fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Oct 22, 2024
1 parent c45c950 commit c3379e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 9 additions & 3 deletions cli/worker/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ func (s *helpPrinter) printHeader(ctx context.Context, sb *strings.Builder, cc c
if cc.Root() == nil {
logz.Fatal("unsatisfied link to root: cc.Root() is invalid", "cc", cc)
}
line := cc.Root().Header()
header := cc.Root().Header()
line := exec.StripLeftTabs(header)
_, _ = sb.WriteString(s.Translate(line, color.FgDefault))
_, _ = sb.WriteString("\n")
_, _, _ = pc, cols, tabbedW
Expand All @@ -213,6 +214,8 @@ func (s *helpPrinter) printDesc(ctx context.Context, sb *strings.Builder, cc cli
desc := cc.DescLong()
if desc != "" {
_, _ = sb.WriteString("\nDescription:\n\n")
desc = exec.StripLeftTabs(desc)
desc = pc.Translate(desc)
line := s.Translate(desc, color.FgDefault)
line = exec.LeftPad(line, 2)
_, _ = sb.WriteString(line)
Expand All @@ -224,7 +227,9 @@ func (s *helpPrinter) printExamples(ctx context.Context, sb *strings.Builder, cc
examples := cc.Examples()
if examples != "" {
_, _ = sb.WriteString("\nExamples:\n\n")
line := s.Translate(examples, color.FgDefault)
str := exec.StripLeftTabs(examples)
str = pc.Translate(str)
line := s.Translate(str, color.FgDefault)
line = exec.LeftPad(line, 2)
_, _ = sb.WriteString(line)
}
Expand All @@ -235,7 +240,8 @@ func (s *helpPrinter) printTailLine(ctx context.Context, sb *strings.Builder, cc
footer := strings.TrimSpace(cc.Root().Footer())
if footer != "" {
_, _ = sb.WriteString("\n")
line := fmt.Sprintf("<dim>%s</dim>", footer)
str := exec.StripLeftTabs(footer)
line := fmt.Sprintf("<dim>%s</dim>", str)
_, _ = sb.WriteString(s.Translate(line, color.FgDefault))
if !strings.HasSuffix(footer, "\n") {
_, _ = sb.WriteString("\n")
Expand Down
1 change: 0 additions & 1 deletion pkg/exec/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func toStringSimple(i interface{}) string {
func StripLeftTabs(s string) string { return stripLeftTabs(s) }

func stripLeftTabs(s string) string {

var lines []string
var tabs int = 1000
var emptyLines []int
Expand Down

0 comments on commit c3379e1

Please sign in to comment.