Skip to content

Commit

Permalink
Cleanup main
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Jul 28, 2018
1 parent 67267aa commit 57b1bb2
Showing 1 changed file with 20 additions and 62 deletions.
82 changes: 20 additions & 62 deletions cmd/dots/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"os"

"github.com/fatih/color"
"github.com/spf13/cobra"

"go.evanpurkhiser.com/dots/config"
Expand All @@ -14,33 +14,30 @@ var (
sourceLockfile *config.SourceLockfile
)

func main() {
path := config.SourceConfigPath()

loadConfigs := func(cmd *cobra.Command, args []string) error {
var err error
func loadConfigs(cmd *cobra.Command, args []string) error {
var err error

sourceConfig, err = config.LoadSourceConfig(path)
if err != nil {
return err
}

sourceLockfile, err = config.LoadLockfile(sourceConfig)
if err != nil {
return err
}
path := config.SourceConfigPath()

errs := config.SanitizeSourceConfig(sourceConfig)
if len(errs) > 0 {
fmt.Println(errs)
}
sourceConfig, err = config.LoadSourceConfig(path)
if err != nil {
return err
}

// TODO: If sanitization fails ask if we should continue anyway on destructive actions
// Maybe ask to show dry run with verbose output before proceeding?
sourceLockfile, err = config.LoadLockfile(sourceConfig)
if err != nil {
return err
}

return nil
warns := config.SanitizeSourceConfig(sourceConfig)
for _, err := range warns {
color.New(color.FgYellow).Fprintf(os.Stderr, "warn: %s\n", err)
}

return nil
}

func main() {
cobra.EnableCommandSorting = false

rootCmd := cobra.Command{
Expand All @@ -57,46 +54,7 @@ func main() {
rootCmd.AddCommand(&configCmd)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
color.New(color.FgRed).Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}

// fmt.Println(lockfile)
//
// configs := resolver.ResolveConfigurations(resolver.Config{
// Groups: source.Groups,
// SourcePath: source.SourcePath,
// OverrideSuffix: source.OverrideSuffix,
// })
//
// fmt.Println(configs["vim/config.vim"])

// TODO: Output writer that looks somthing like
//
// source: /home/.local/etc
// install: /home/.config
//
// [=> base] -- bash/bashrc
// [=> composed] -- bash/environment
// -> composing from base and machines/desktop groups
// [=> removed] -- bash/bad-filemulti
// [=> compiled] -- bash/complex
// -> ignoring configs in base and common/work due to override
// -> override file present in common/work-vm
// -> composing from machines/crunchydev (spliced at common/work-vm:22)
//
// [=> install script] base/bash.install
// -> triggered by base/bash/bashrc
// -> triggered by base/bash/environment

// CLI Interfaceo

// dots {config, install, diff, files, help}

// dots install [filter...]
// dots diff [filter...]
// dots files [filter...]

// dots config {profiles, groups, use, override}

}

0 comments on commit 57b1bb2

Please sign in to comment.