Skip to content

Commit

Permalink
Replace global 'version' flag with VERSION
Browse files Browse the repository at this point in the history
More consistent with other global flags.

I thought about removing the long name entirely and just having -V, so I
made some slight changes in the usage generation code to support that,
but ultimately decided against that for this flag.

Now our release script can safely have an arg named 'version' so we
rename the 'new_version' one to that.
  • Loading branch information
amterp committed Nov 22, 2024
1 parent 2191687 commit 6108c21
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions core/flags_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
FlagStdinScriptName StringRslArg
FlagMockResponse MockResponseRslArg

// ordering here matters -- it's the order in which they are printed in the usage string
Flags = []RslArg{
&FlagHelp,
&FlagDebug,
Expand All @@ -32,8 +33,7 @@ func CreateAndRegisterGlobalFlags() []RslArg {
FlagNoColor = NewBoolRadArg("NO-COLOR", "", "Disable colorized output.", false)
FlagQuiet = NewBoolRadArg("QUIET", "Q", "Suppresses some output.", false)
FlagShell = NewBoolRadArg("SHELL", "", "Outputs shell/bash exports of variables, so they can be eval'd", false)
// todo the --version flag is inconsistent in its capitalization, maybe don't have it? Just the shorthand?
FlagVersion = NewBoolRadArg("version", "V", "Print rad version information.", false)
FlagVersion = NewBoolRadArg("VERSION", "V", "Print rad version information.", false)
FlagStdinScriptName = NewStringRadArg("STDIN", "", "script-name", "Enables reading RSL from stdin, and takes a string arg to be treated as the 'script name'.", "")
FlagMockResponse = NewMockResponseRadArg("MOCK-RESPONSE", "", "Add mock response for json requests (pattern:filePath)")
registerGlobalFlags()
Expand Down
8 changes: 5 additions & 3 deletions core/runner_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (r *RadRunner) RunUsageExit() {
func (r *RadRunner) printScriptlessUsage() {
buf := new(bytes.Buffer)

fmt.Fprintf(buf, "Request And Display (RAD): A tool for writing user-friendly command line scripts.\n\n")
fmt.Fprintf(buf, "rad: A tool for writing user-friendly command line scripts.\n\n")
greenBold(buf, "Usage:\n")
bold(buf, " rad")
cyan(buf, " [script path] [flags]\n\n")
Expand Down Expand Up @@ -88,10 +88,12 @@ func flagUsage(buf *bytes.Buffer, flags []RslArg) {
}

line := ""
if f.GetShort() != "" {
if f.GetShort() != "" && f.GetName() != "" {
line = fmt.Sprintf(" -%s, --%s", f.GetShort(), f.GetName())
} else {
} else if f.GetShort() == "" {
line = fmt.Sprintf(" --%s", f.GetName())
} else if f.GetName() == "" {
line = fmt.Sprintf(" -%s", f.GetShort())
}

argUsage := f.GetArgUsage()
Expand Down
2 changes: 1 addition & 1 deletion core/testing/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Global flags:
--NO-COLOR Disable colorized output.
-Q, --QUIET Suppresses some output.
--SHELL Outputs shell/bash exports of variables, so they can be eval'd
-V, --version Print rad version information.
-V, --VERSION Print rad version information.
--MOCK-RESPONSE string Add mock response for json requests (pattern:filePath)
`
assertOnlyOutput(t, stdErrBuffer, expected)
Expand Down
4 changes: 2 additions & 2 deletions core/testing/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ print("{-12}")
}

func TestMisc_Version(t *testing.T) {
setupAndRunCode(t, "", "--version")
setupAndRunCode(t, "", "--VERSION")
assertOnlyOutput(t, stdErrBuffer, "rad version "+core.Version+"\n")
assertNoErrors(t)
resetTestState()
Expand All @@ -64,7 +64,7 @@ func TestMisc_VersionShort(t *testing.T) {

func TestMisc_PrioritizesHelpIfBothHelpAndVersionSpecified(t *testing.T) {
setupAndRunCode(t, "", "-h", "-V", "--NO-COLOR")
expected := `Request And Display (RAD): A tool for writing user-friendly command line scripts.
expected := `rad: A tool for writing user-friendly command line scripts.
Usage:
rad [script path] [flags]
Expand Down
2 changes: 1 addition & 1 deletion core/testing/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const globalFlagHelp = `Global flags:
--NO-COLOR Disable colorized output.
-Q, --QUIET Suppresses some output.
--SHELL Outputs shell/bash exports of variables, so they can be eval'd
-V, --version Print rad version information.
-V, --VERSION Print rad version information.
--STDIN script-name Enables reading RSL from stdin, and takes a string arg to be treated as the 'script name'.
--MOCK-RESPONSE string Add mock response for json requests (pattern:filePath)
`
Expand Down
8 changes: 4 additions & 4 deletions new_release.rsl → release.rsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Bumps the version in rad, creates a commit, tags it, and optionally pushes it
This will trigger a GitHub action to create a homebrew-rad PR with the new version
---
args:
new_version string # The new release version to bump to
version string # The new release version to bump to
push p bool # Whether or not a push should also be performed

// Build & test
Expand All @@ -17,13 +17,13 @@ fail:
path = "./core/version.go"

// Update Version in ./core/version.go
$`sed -i '' "s/Version = \".*\"/Version = \"{new_version}\"/" {path}`
$`sed -i '' "s/Version = \".*\"/Version = \"{version}\"/" {path}`
fail:
print("❌ Failed to update version in code!")

$!`git add {path}`
$!`git commit -m "Bump version to {new_version}" {path}`
$!`git tag -a "{new_version}" -m "Bump version to {new_version}"`
$!`git commit -m "Bump version to {version}" {path}`
$!`git tag -a "{version}" -m "Bump version to {version}"`

if push:
$`./push.rsl`
Expand Down

0 comments on commit 6108c21

Please sign in to comment.