From 0b789019b045e467385b210a13284c96946ab31e Mon Sep 17 00:00:00 2001 From: blacktop Date: Wed, 27 Dec 2017 12:09:37 -0700 Subject: [PATCH] fixes --- .vscode/launch.json | 3 +- Makefile | 2 +- launch.go | 151 ++++++++++++++++++++++---------------------- 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index cde3374..61b4494 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,8 @@ "program": "${workspaceRoot}", "args": [ "-V", - "default" + "load", + "launchpad.yaml" ] } ] diff --git a/Makefile b/Makefile index 5483094..44dfd73 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ setup: ## Install all the build and lint dependencies test: ## Run all the tests scripts/reset.sh - go run *.go -V default + go run *.go -V load launchpad.yaml # gotestcover $(TEST_OPTIONS) -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s cover: test ## Run all the tests and opens the coverage report diff --git a/launch.go b/launch.go index e3b9e41..93329a5 100644 --- a/launch.go +++ b/launch.go @@ -30,16 +30,83 @@ var ( // CmdDefaultOrg will organize your launchpad by the app default categories func CmdDefaultOrg(verbose bool) error { + log.Info("IMPLIMENT DEFAULT ORG HERE <=================") + return nil +} + +// CmdSaveConfig will save your launchpad settings to a config file +func CmdSaveConfig(verbose bool) error { + log.Info("IMPLIMENT SAVING TO CONFIG YAML HERE <=================") + // var items []Item + // var group Group + // appGroups := make(map[string][]string) + + // if err := db.Where("type = ?", "4").Find(&items).Error; err != nil { + // log.WithError(err).Error("find item of type=4 failed") + // } + + // for _, item := range items { + // group = Group{} + // db.Model(&item).Related(&item.App) + // db.Model(&item.App).Related(&item.App.Category) + // log.WithFields(log.Fields{ + // "app_id": item.App.ItemID, + // "app_name": item.App.Title, + // "parent_id": item.ParentID - 1, + // }).Debug("parsing item") + // if err := db.First(&group, item.ParentID-1).Error; err != nil { + // log.WithError(err).WithFields(log.Fields{"ParentID": item.ParentID - 1}).Debug("find group failed") + // continue + // } + // log.WithFields(log.Fields{ + // "group_id": group.ID, + // "group_name": group.Title, + // }).Debug("parsing group") + // item.Group = group + // if len(group.Title) > 0 { + // appGroups[group.Title] = append(appGroups[group.Title], item.App.Title) + // } + // } + + // fmt.Println("--------------------------------------------------------") + + // fmt.Printf("item========================================> %+v\n", item) + // itemJSON, _ := json.Marshal(item) + // fmt.Println(string(itemJSON)) + // fmt.Printf("%+v\n", item.App) + + // write out to TOML + // checkError(writeTomlFile("./launchpad.toml", item)) + // if err := db.Find(&groups).Error; err != nil { + // log.Error(err) + // } + // g := make(map[string][]Group) + // g["Groups"] = groups + + ////////////////////////////////////////////////// TODO: write config out to YAML + // d, err := yaml.Marshal(&appGroups) + // if err != nil { + // return errors.Wrap(err, "unable to marshall YAML") + // } + + // if err = ioutil.WriteFile("launchpad.yaml", d, 0644); err != nil { + // return err + // } + + log.Infof(bold, strings.ToUpper("successfully wrote launchpad.yaml")) + + return nil +} + +// CmdLoadConfig will load your launchpad settings from a config file +func CmdLoadConfig(verbose bool, configFile string) error { log.Infof(bold, "[PARSE LAUCHPAD DATABASE]") + if verbose { log.SetLevel(log.DebugLevel) } - // var items []Item - // var group Group - // appGroups := make(map[string][]string) - // Older macOS //////////////////////////////// // $HOME/Library/Application\ Support/Dock/*.db @@ -92,7 +159,7 @@ func CmdDefaultOrg(verbose bool) error { groupID := math.Max(float64(lpad.GetMaxAppID()), float64(lpad.GetMaxWidgetID())) // Read in Config file - config, err := database.LoadConfig("launchpad.yaml") + config, err := database.LoadConfig(configFile) if err != nil { log.WithError(err).Fatal("database.LoadConfig") } @@ -109,73 +176,6 @@ func CmdDefaultOrg(verbose bool) error { return restartDock() } -// CmdSaveConfig will save your launchpad settings to a config file -func CmdSaveConfig(verbose bool) error { - log.Info("IMPLIMENT SAVING TO CONFIG YAML HERE <=================") - - // if err := db.Where("type = ?", "4").Find(&items).Error; err != nil { - // log.WithError(err).Error("find item of type=4 failed") - // } - - // for _, item := range items { - // group = Group{} - // db.Model(&item).Related(&item.App) - // db.Model(&item.App).Related(&item.App.Category) - // log.WithFields(log.Fields{ - // "app_id": item.App.ItemID, - // "app_name": item.App.Title, - // "parent_id": item.ParentID - 1, - // }).Debug("parsing item") - // if err := db.First(&group, item.ParentID-1).Error; err != nil { - // log.WithError(err).WithFields(log.Fields{"ParentID": item.ParentID - 1}).Debug("find group failed") - // continue - // } - // log.WithFields(log.Fields{ - // "group_id": group.ID, - // "group_name": group.Title, - // }).Debug("parsing group") - // item.Group = group - // if len(group.Title) > 0 { - // appGroups[group.Title] = append(appGroups[group.Title], item.App.Title) - // } - // } - - // fmt.Println("--------------------------------------------------------") - - // fmt.Printf("item========================================> %+v\n", item) - // itemJSON, _ := json.Marshal(item) - // fmt.Println(string(itemJSON)) - // fmt.Printf("%+v\n", item.App) - - // write out to TOML - // checkError(writeTomlFile("./launchpad.toml", item)) - // if err := db.Find(&groups).Error; err != nil { - // log.Error(err) - // } - // g := make(map[string][]Group) - // g["Groups"] = groups - - ////////////////////////////////////////////////// TODO: write config out to YAML - // d, err := yaml.Marshal(&appGroups) - // if err != nil { - // return errors.Wrap(err, "unable to marshall YAML") - // } - - // if err = ioutil.WriteFile("launchpad.yaml", d, 0644); err != nil { - // return err - // } - - log.Infof(bold, strings.ToUpper("successfully wrote launchpad.yaml")) - - return nil -} - -// CmdLoadConfig will load your launchpad settings from a config file -func CmdLoadConfig(verbose bool, configFile string) error { - log.Info("IMPLIMENT LOADING FROM CONFIG YAML HERE <=================") - return nil -} - func init() { log.SetHandler(clihander.Default) } @@ -219,19 +219,20 @@ func main() { Name: "default", Usage: "Organize by Categories", Action: func(c *cli.Context) error { + fmt.Println(porg) return CmdDefaultOrg(c.GlobalBool("verbose")) }, }, { Name: "save", - Usage: "Save Current Launchpad App Config", + Usage: "Save Current Launchpad Settings Config", Action: func(c *cli.Context) error { return CmdSaveConfig(c.GlobalBool("verbose")) }, }, { Name: "load", - Usage: "Load Launchpad App Config From File", + Usage: "Load Launchpad Settings Config From File", Action: func(c *cli.Context) error { if c.Args().Present() { // user supplied launchpad config YAML @@ -239,7 +240,6 @@ func main() { if err != nil { return err } - fmt.Println(porg) } else { cli.ShowAppHelp(c) } @@ -248,7 +248,6 @@ func main() { }, } app.Action = func(c *cli.Context) error { - if !c.Args().Present() { cli.ShowAppHelp(c) }