Skip to content

Commit

Permalink
Expand verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Aug 7, 2019
1 parent c2db7d5 commit c9f036d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
7 changes: 2 additions & 5 deletions cmd/dots/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var installCmd = cobra.Command{
forceReInstall, _ := cmd.Flags().GetBool("reinstall")
verbose, _ := cmd.Flags().GetBool("verbose")
dryRun, _ := cmd.Flags().GetBool("dry-run")
info, _ := cmd.Flags().GetBool("info")

dotfiles := resolver.ResolveDotfiles(*sourceConfig, *sourceLockfile).Filter(args)
prepared := installer.PrepareDotfiles(dotfiles, *sourceConfig)
Expand All @@ -31,7 +30,6 @@ var installCmd = cobra.Command{
InstallConfig: installConfig,
PreparedInstall: prepared,
IsVerbose: verbose,
IsInfo: info || verbose || dryRun,
})

if dryRun {
Expand All @@ -55,7 +53,6 @@ func init() {
flags.SortFlags = false

flags.BoolP("reinstall", "r", false, "forces execution of all installation scripts")
flags.BoolP("info", "i", false, "prints install operation details")
flags.BoolP("verbose", "v", false, "prints debug data, implies info")
flags.BoolP("dry-run", "n", false, "do not mutate any dotfiles, implies info")
flags.BoolP("verbose", "v", false, "prints debug data")
flags.BoolP("dry-run", "n", false, "do not mutate any dotfiles, implies verbose")
}
44 changes: 37 additions & 7 deletions output/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import (
"go.evanpurkhiser.com/dots/installer"
)

var e = color.RedString("errs:")
var w = color.YellowString("warn:")
var n = color.CyanString("note:")

// Config is a object used to configure the output logger.
type Config struct {
SourceConfig config.SourceConfig
InstallConfig installer.InstallConfig
PreparedInstall installer.PreparedInstall
IsVerbose bool
IsInfo bool
}

// New creates a output logger given a configuration.
Expand Down Expand Up @@ -84,7 +87,7 @@ func (l *Output) InstallInfo() {
// output anything without IsInfo. When IsVerbose is enabled additional
// information about the prepared dotfile will be included.
func (l *Output) DotfileInfo(dotfile *installer.PreparedDotfile) {
if !l.IsInfo {
if !l.IsVerbose {
return
}

Expand Down Expand Up @@ -130,21 +133,48 @@ func (l *Output) DotfileInfo(dotfile *installer.PreparedDotfile) {
color.HiBlackString("]"),
)

output := fmt.Sprintf(" %%s %%-%ds %%s\n", l.maxDotfileLength+1)
output := fmt.Sprintf(" %%s %%-%ds %%s", l.maxDotfileLength+1)
fmt.Printf(
output,
indicatorColor.Sprint(indicator),
dotfile.Path,
group,
)

if dotfile.Permissions.IsChanged() {
fmt.Printf(
" [%s %s %s]",
color.New(color.FgHiRed).Sprintf("%#o", int(dotfile.Permissions.Old)),
color.HiWhiteString("→"),
color.New(color.FgHiGreen).Sprintf("%#o", int(dotfile.Permissions.New)),
)
}

ln(n, dotfile.Mode.Old.String())

ln := func(v ...interface{}) {
fmt.Printf(" %s %s\n", v...)
}

fmt.Println()

if dotfile.PrepareError != nil {
fmt.Printf(" %s", color.RedString(dotfile.PrepareError.Error()))
ln(e, color.HiRedString(dotfile.PrepareError.Error()))
}

if !l.IsVerbose {
return
if dotfile.SourcesAreIrregular {
ln(e, "source files are irregular")
}

if dotfile.OverwritesExisting {
ln(w, "ovewriting existing file")
}

if dotfile.SourcePermissionsDiffer {
ln(w, "inconsistent source file permissions")
}

// TODO: Implement all verbosity outputs here
if dotfile.RemovedNull {
ln(n, "nothing to remove")
}
}

0 comments on commit c9f036d

Please sign in to comment.