-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add "sbx help <cmd>"; parse command args
this adds `sbx help <cmd>` to get more info on what a command does (for example, what flags it accepts). this is a precursor to add a `duration` flag to `up`, as this sets us up to add documented flags to the `up` command. under the hood, this also adds the ability to parse additional args for each command (right now, only `help` uses this).
- Loading branch information
Showing
24 changed files
with
213 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package help | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/reverbdotcom/sbx/up" | ||
) | ||
|
||
type HelpFn func() (string, error) | ||
|
||
const Help = `NAME | ||
sbx - orchestra cli | ||
COMMANDS | ||
sbx help | ||
up | ||
down | ||
name | ||
dash | ||
logs | ||
web | ||
graphiql | ||
version | ||
info | ||
progress | ||
DESCRIPTION | ||
command shorthand description | ||
help h show the help message. use "sbx help <cmd>" for more info about that command. | ||
up u spin up an orchestra sandbox. | ||
down tear down an orchestra sandbox. | ||
name n show the sandbox name. | ||
dash d open the dashboard in a browser. | ||
logs l open the logs in a browser. | ||
web w open the site in a browser. | ||
graphiql g open graphql user interface in a browser. | ||
version v show the version of the sbx cli. | ||
info i show the summary of the sandbox. | ||
progress p open deployment progress in a browser. | ||
USAGE: | ||
sbx up | ||
sbx name | ||
` | ||
|
||
func Run(cmdArgs []string) (string, error) { | ||
var totalArgs = len(cmdArgs) | ||
if totalArgs == 0 { | ||
return Help, nil | ||
} | ||
|
||
if totalArgs > 1 { | ||
return "", fmt.Errorf("too many arguments") | ||
} | ||
|
||
var cmd = cmdArgs[0] | ||
var helpFn = helps()[cmd] | ||
if helpFn == nil { | ||
return fmt.Sprintf("no help info available for command %s", cmd), nil | ||
} | ||
|
||
return helpFn() | ||
} | ||
|
||
func helps() map[string]HelpFn { | ||
return map[string]HelpFn{ | ||
"up": up.Help, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package help | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/reverbdotcom/sbx/up" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
t.Run("it returns generic help text with no args", func(t *testing.T) { | ||
output, err := Run([]string{}) | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error %v", err) | ||
} | ||
|
||
if output != Help { | ||
t.Errorf("did not return generic help text, got %v", output) | ||
} | ||
}) | ||
|
||
t.Run("it fails when there's too many args", func(t *testing.T) { | ||
output, err := Run([]string{"up", "foo"}) | ||
if err == nil { | ||
t.Errorf("help should have errored, but got %v", output) | ||
} | ||
}) | ||
|
||
t.Run("it returns help text for command", func(t *testing.T) { | ||
output, err := Run([]string{"up"}) | ||
if err != nil { | ||
t.Errorf("unexpected error %v", err) | ||
} | ||
|
||
text, _ := up.Help() | ||
if output != text { | ||
t.Errorf("did not return help text for up, got %v", output) | ||
} | ||
}) | ||
|
||
t.Run("it reports when command has no help info", func(t *testing.T) { | ||
output, err := Run([]string{"foo"}) | ||
if err != nil { | ||
t.Errorf("unexpected error %v", err) | ||
} | ||
|
||
if !strings.Contains(output, "no help info") { | ||
t.Errorf("expected to report no help info for command, but got %v", output) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.