Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Dec 27, 2017
1 parent 2d03b6c commit 0b78901
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"program": "${workspaceRoot}",
"args": [
"-V",
"default"
"load",
"launchpad.yaml"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
151 changes: 75 additions & 76 deletions launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -219,27 +219,27 @@ 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
err := CmdLoadConfig(c.Bool("verbose"), c.Args().First())
if err != nil {
return err
}
fmt.Println(porg)
} else {
cli.ShowAppHelp(c)
}
Expand All @@ -248,7 +248,6 @@ func main() {
},
}
app.Action = func(c *cli.Context) error {

if !c.Args().Present() {
cli.ShowAppHelp(c)
}
Expand Down

0 comments on commit 0b78901

Please sign in to comment.