From c0044cc1c7b9973b531e157e821e3194dbb1fb35 Mon Sep 17 00:00:00 2001 From: Hans Alves Date: Sat, 12 May 2018 13:52:51 +0200 Subject: [PATCH 1/2] Allow creation of triggers and VF components --- command/create.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/command/create.go b/command/create.go index d02b0aee..ec464fa8 100644 --- a/command/create.go +++ b/command/create.go @@ -18,17 +18,26 @@ Examples (both flags are required): force create -w ApexClass -n NewController + force create -w ApexTrigger -n NewTrigger -s Account + force create -w ApexPage -n CoolPage + + force create -w ApexComponent -n CoolComponent `, } var ( what string + sObjectName string itemName string ) func init() { cmdCreate.Flag.StringVar(&what, "what", "", "What type of thing to create (currently only Apex or Visualforce).") cmdCreate.Flag.StringVar(&what, "w", "", "What type of thing to create (currently only Apex or Visualforce).") + cmdCreate.Flag.StringVar(&what, "type", "", "What type of thing to create (currently only Apex or Visualforce).") // Because consistency with other commands like fetch + cmdCreate.Flag.StringVar(&what, "t", "", "What type of thing to create (currently only Apex or Visualforce).") + cmdCreate.Flag.StringVar(&sObjectName, "sobject", "", "For which sobject should the thing be created (only for Triggers).") + cmdCreate.Flag.StringVar(&sObjectName, "s", "", "For which sobject should the thing be created (only for Triggers).") cmdCreate.Flag.StringVar(&itemName, "n", "", "Name of thing to be created.") cmdCreate.Flag.StringVar(&itemName, "name", "", "Name of thing to be created.") cmdCreate.Run = runCreate @@ -43,6 +52,14 @@ func runCreate(cmd *Command, args []string) { switch strings.ToLower(what) { case "apexclass": attrs = getApexDefinition() + case "apextrigger": + if len(sObjectName) == 0 { + cmd.PrintUsage() + return + } + attrs = getTriggerDefinition() + case "apexcomponent": + attrs = getVFComponentDefinition() case "visualforce", "apexpage": what = "apexpage" attrs = getVFDefinition() @@ -59,7 +76,6 @@ func runCreate(cmd *Command, args []string) { } func getVFDefinition() (attrs map[string]string) { - //{ "markup": " ", "name": "mytestpage", "masterlabel": "Test Page" } attrs = make(map[string]string) attrs["markup"] = "\n\n" attrs["name"] = itemName @@ -67,12 +83,28 @@ func getVFDefinition() (attrs map[string]string) { return } +func getVFComponentDefinition() (attrs map[string]string) { + attrs = make(map[string]string) + attrs["markup"] = "\n\n" + attrs["name"] = itemName + attrs["masterlabel"] = strings.Replace(itemName, " ", "_", -1) + return +} + func getApexDefinition() (attrs map[string]string) { - //{ "markup": " ", "name": "mytestpage", "masterlabel": "Test Page" } attrs = make(map[string]string) attrs["status"] = "Active" attrs["body"] = fmt.Sprintf("public with sharing class %s {\n\n}", itemName) attrs["name"] = itemName + return +} + +func getTriggerDefinition() (attrs map[string]string) { + //{ "markup": " ", "name": "mytestpage", "masterlabel": "Test Page" } + attrs = make(map[string]string) + attrs["status"] = "Active" + attrs["body"] = fmt.Sprintf("trigger %s on %s (before insert, after insert, before update, after update, before delete, after delete, after undelete) { \n\n }", itemName, sObjectName) attrs["name"] = itemName + attrs["TableEnumOrId"] = sObjectName return } From ff1fc2253cf17fbff01f8c609f0b2a72798e20c7 Mon Sep 17 00:00:00 2001 From: Hans Alves Date: Wed, 27 Jun 2018 09:51:44 +0200 Subject: [PATCH 2/2] Added browser parameter to open command. --- command/open.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/command/open.go b/command/open.go index 7002d6c7..4f1786a1 100644 --- a/command/open.go +++ b/command/open.go @@ -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" @@ -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 } @@ -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() +}