From c5185060f8a0fcbc6fe0a9abb8ed8647ee806322 Mon Sep 17 00:00:00 2001 From: Andrew Lunde Date: Fri, 25 Sep 2020 17:48:12 -0400 Subject: [PATCH] windoz OK --- README.md | 2 ++ ServiceManagement_plugin.go | 31 +++++++++-------- windoz_file.go | 66 +++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 windoz_file.go diff --git a/README.md b/README.md index 14730cd..a293905 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ This is a Cloud Foundry CLI plugin designed to make it easier when using the [Se # Requirements Installed CloudFoundry CLI - ensure that CloudFoundry CLI is installed and working. For more information about installation of CloudFoundry CLI, please visit the official CloudFoundry [documentation](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html). +If you are running from within VSCode, you need to create a Workspace before using the -m (Modify settings.json) option. + # Download and Installation Check whether you have a previous version installed, using the command: `cf plugins`. If the ServiceManagement plugin is already installed, you need to uninstall it first and then to install the new version. You can uninstall the plugin using command `cf uninstall-plugin ServiceManagement`. diff --git a/ServiceManagement_plugin.go b/ServiceManagement_plugin.go index 31c1b49..9dbc8ab 100644 --- a/ServiceManagement_plugin.go +++ b/ServiceManagement_plugin.go @@ -551,21 +551,26 @@ func (c *ServiceManagementPlugin) Run(cliConnection plugin.CliConnection, args [ case "windows": fmt.Println("On Windoz:") + + appData := os.Getenv("APPDATA") + fmt.Printf("appData: %s\n", appData) + //APPDATA=C:\Users\I830671\AppData\Roaming - // defaultsFile = "\"" + homeDirectory + "\\AppData\\Roaming\\Code\\storage.json" + "\"" - // fmt.Println("defaultsFile: " + defaultsFile) - // byteValue, err := ioutil.ReadFile(defaultsFile) - // if err == nil { - // configURIPath, err := jsonparser.GetString(byteValue, "windowsState", "lastActiveWindow", "workspaceIdentifier", "configURIPath") - // if err == nil { - // fmt.Println("configURIPath: " + configURIPath) - // settingsFile = "/" + strings.TrimLeft(configURIPath, "file:/") - // inSettings = true // File has sqltools.connections at the top-level - // } - // } - settingsFile = "\"" + homeDirectory + "\\AppData\\Roaming\\Code\\User\\settings.json" + "\"" - inSettings = false // File has sqltools.connections at the top-level + defaultsFile = appData + "/Code/storage.json" + fmt.Println("defaultsFile: " + defaultsFile) + + byteValue, err := ioutil.ReadFile(defaultsFile) + if err == nil { + configURIPath, err := jsonparser.GetString(byteValue, "windowsState", "lastActiveWindow", "workspaceIdentifier", "configURIPath") + if err == nil { + fmt.Println("configURIPath: " + configURIPath) + settingsFile = strings.TrimLeft(configURIPath, "file:/") + settingsFile = strings.Replace(settingsFile, "%3A", ":", -1) + //fmt.Println("settingsFile: " + settingsFile) + inSettings = true // File has sqltools.connections at the top-level + } + } } fmt.Println("settingsFile: " + settingsFile) diff --git a/windoz_file.go b/windoz_file.go new file mode 100644 index 0000000..02e7f57 --- /dev/null +++ b/windoz_file.go @@ -0,0 +1,66 @@ +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "os/user" + "runtime" + "strings" + + "github.com/buger/jsonparser" +) + +func handleError(err error) { + if err != nil { + fmt.Fprintln(os.Stderr, "Error:", err) + os.Exit(1) + } +} + +func main() { + fmt.Println(runtime.GOOS) + fmt.Println(runtime.GOARCH) + + user, err := user.Current() + if err != nil { + log.Fatalf(err.Error()) + } + homeDirectory := user.HomeDir + fmt.Printf("Home Directory: %s\n", homeDirectory) + + appData := os.Getenv("APPDATA") + fmt.Printf("appData: %s\n", appData) + + var defaultsFile = "Unknown" + //var defaultsExists = false + + var settingsFile = "Unknown" + + defaultsFile = appData + "/Code/storage.json" + + fmt.Println("defaultsFile: " + defaultsFile) + + _, err = os.Stat(defaultsFile) + handleError(err) + + byteValue, err := ioutil.ReadFile(defaultsFile) + if err == nil { + configURIPath, err := jsonparser.GetString(byteValue, "windowsState", "lastActiveWindow", "workspaceIdentifier", "configURIPath") + if err == nil { + fmt.Println("configURIPath: " + configURIPath) + settingsFile = strings.TrimLeft(configURIPath, "file:/") + } + } + + settingsFile = strings.Replace(settingsFile, "%3A", ":", -1) + + fmt.Println("settingsFile: " + settingsFile) + + _, err = os.Stat(settingsFile) + handleError(err) + + fmt.Println("OK: Done.") + +}