Skip to content

Commit

Permalink
Print one-liner description in usage if no block description
Browse files Browse the repository at this point in the history
Still need to revisit this whole 'one liner' and 'block description'
split, but right now, if you specify e.g.

   ---
   some description
   ---

in a script, then this description doesn't get printed at all because it
gets put into the 'one liner' field, and we leave the block empty, but
in our usage logic, we only look at the block currently.

In this commit, we fall back to the one-liner if it's there and the
block description is not.
  • Loading branch information
amterp committed Dec 21, 2024
1 parent 2339fbf commit 13e0694
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
2 changes: 2 additions & 0 deletions core/runner_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (r *RadRunner) printScriptUsage() {

if r.scriptMetadata.BlockDescription != nil {
fmt.Fprintf(buf, *r.scriptMetadata.BlockDescription+"\n\n")
} else if r.scriptMetadata.OneLineDescription != nil {
fmt.Fprintf(buf, *r.scriptMetadata.OneLineDescription+"\n\n")
}

greenBold(buf, "Usage:\n")
Expand Down
53 changes: 53 additions & 0 deletions core/testing/file_header_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package testing

import "testing"

func Test_FileHeader_PrintsOneLinerIfOnlyThat(t *testing.T) {
rsl := `
---
This is a one liner!
---
args:
name string
`
setupAndRunCode(t, rsl, "-h", "--NO-COLOR")
expected := `This is a one liner!
Usage:
test <name>
Script args:
--name string
` + globalFlagHelp
assertOnlyOutput(t, stdErrBuffer, expected)
assertNoErrors(t)
resetTestState()
}

func Test_FileHeader_PrintsExtra(t *testing.T) {
rsl := `
---
This is a one liner!
Here is
the rest!
---
args:
name string
`
setupAndRunCode(t, rsl, "-h", "--NO-COLOR")
expected := `Here is
the rest!
Usage:
test <name>
Script args:
--name string
` + globalFlagHelp
assertOnlyOutput(t, stdErrBuffer, expected)
assertNoErrors(t)
resetTestState()
}
27 changes: 21 additions & 6 deletions docs-web/docs/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@ title: Strings

- Not all strings are just plain text. They may have attributes such as color.
- This means that RSL contains logic on how to handle attributes when strings are combined or operated on
- e.g. concatenation, slicing, replace functions, etc
- e.g. concatenation, slicing, replace functions, etc
- The following operations maintain color attributes:
- concatenation
- index lookup
- concatenation
- index lookup
- The following *do not*, and just return a plain string:
- slicing (to be added)
- functions: `replace`, `split`
- slicing (to be added)
- functions: `replace`, `split`
- Attributes do *not* impact things like equality or comparing strings.
- A green string "Alice" and a yellow string "Alice" will be considered 'equal'.
- A green string "Alice" and a yellow string "Alice" will be considered 'equal'.

## Formatting

- Float formatting does *not* require a `f` at the end.
- Correct: `{myFloat:.2}`
- Incorrect: `{myFloat:.2f}`

Examples:

```rsl
"{myString:20}"
"{myString:<20}"
"{myString:>20}"
"{myFloat:.2}"
```

0 comments on commit 13e0694

Please sign in to comment.