Skip to content
Open

Open #529

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions command/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Examples:
`,
}
var (
what string
what string
sObjectName string
itemName string
itemName string
)

func init() {
Expand Down
23 changes: 22 additions & 1 deletion command/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package command

import (
"fmt"
"strings"
"os/exec"
desktop "github.com/ForceCLI/force/desktop"
. "github.com/ForceCLI/force/error"
. "github.com/ForceCLI/force/lib"
Expand All @@ -15,10 +17,18 @@ Open a browser window, logged into an authenticated Salesforce org.
By default, the active account is used.

force open [account]
force open -b firefox
force open -b "firefox --private-window"
force open --browser google-chrome
`,
}
var (
browser string
)

func init() {
cmdOpen.Flag.StringVar(&browser, "browser", "", "Command for the browser to open instead of the system default.")
cmdOpen.Flag.StringVar(&browser, "b", "", "Command for the browser to open instead of the system default.")
cmdOpen.Run = runOpen
}

Expand All @@ -38,8 +48,19 @@ func runOpen(cmd *Command, args []string) {
ErrorAndExit(err.Error())
}
url := fmt.Sprintf("%s/secur/frontdoor.jsp?sid=%s", force.Credentials.InstanceUrl, force.Credentials.AccessToken)
err = desktop.Open(url)
if len(browser) != 0 {
err = openBrowser(browser, url)
} else {
err = desktop.Open(url)
}
if err != nil {
ErrorAndExit(err.Error())
}
}

func openBrowser(browser string, url string) error {
run := strings.Fields(browser)
run = append(run, url)
cmd := exec.Command(run[0], run[1:]...)
return cmd.Start()
}