open: StartWith() and RunWith() revert to default if appName is empty

This commit is contained in:
technoweenie 2020-02-21 07:25:01 -07:00
parent eef8423979
commit c533344a20
2 changed files with 20 additions and 2 deletions

View File

@ -38,6 +38,9 @@ func Start(input string) error {
Wait for the open command to complete. Wait for the open command to complete.
*/ */
func RunWith(input string, appName string) error { func RunWith(input string, appName string) error {
if len(appName) == 0 {
return Run(input)
}
return openWith(input, appName).Run() return openWith(input, appName).Run()
} }
@ -46,5 +49,8 @@ func RunWith(input string, appName string) error {
Don't wait for the open command to complete. Don't wait for the open command to complete.
*/ */
func StartWith(input string, appName string) error { func StartWith(input string, appName string) error {
if len(appName) == 0 {
return Start(input)
}
return openWith(input, appName).Start() return openWith(input, appName).Start()
} }

View File

@ -37,8 +37,14 @@ func TestStart(t *testing.T) {
func TestRunWith(t *testing.T) { func TestRunWith(t *testing.T) {
// shouldn't error // shouldn't error
input := "https://google.com/" input := "https://google.com/"
err := RunWith(input, "")
if err != nil {
t.Errorf("open.RunWith(\"%s\", \"\") threw an error: %s", input, err)
}
// shouldn't error
app := "firefox" app := "firefox"
err := RunWith(input, app) err = RunWith(input, app)
if err != nil { if err != nil {
t.Errorf("open.RunWith(\"%s\", \"%s\") threw an error: %s", input, app, err) t.Errorf("open.RunWith(\"%s\", \"%s\") threw an error: %s", input, app, err)
} }
@ -54,8 +60,14 @@ func TestRunWith(t *testing.T) {
func TestStartWith(t *testing.T) { func TestStartWith(t *testing.T) {
// shouldn't error // shouldn't error
input := "https://google.com/" input := "https://google.com/"
err := StartWith(input, "")
if err != nil {
t.Errorf("open.StartWith(\"%s\", \"\") threw an error: %s", input, err)
}
// shouldn't error
app := "firefox" app := "firefox"
err := StartWith(input, app) err = StartWith(input, app)
if err != nil { if err != nil {
t.Errorf("open.StartWith(\"%s\", \"%s\") threw an error: %s", input, app, err) t.Errorf("open.StartWith(\"%s\", \"%s\") threw an error: %s", input, app, err)
} }