github.com/haagen/force@v0.19.6-0.20140911230915-22addd930b34/active.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "sort" 6 ) 7 8 var cmdActive = &Command{ 9 Run: runActive, 10 Usage: "active [account]", 11 Short: "Show or set the active force.com account", 12 Long: ` 13 Set the active force.com account 14 15 Examples: 16 17 force active 18 force active user@example.org 19 `, 20 } 21 22 func runActive(cmd *Command, args []string) { 23 if len(args) == 0 { 24 account, _ := Config.Load("current", "account") 25 fmt.Println(account) 26 } else { 27 account := args[0] 28 accounts, _ := Config.List("accounts") 29 i := sort.SearchStrings(accounts, account) 30 if i < len(accounts) && accounts[i] == account { 31 Config.Save("current", "account", account) 32 } else { 33 ErrorAndExit(fmt.Sprintf("no such account %s\n", account)) 34 } 35 } 36 }