aboutsummaryrefslogtreecommitdiffstats
path: root/dotfiles.py
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-04 13:18:32 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-04 13:18:32 -0500
commitdac08d6522270d4ad312efabdba02aff121af1e3 (patch)
treeb2adac7e8fc381f5241e83ad4f9f982500330ed1 /dotfiles.py
parentce3e697f8da61afd5a8fab377983d69abb20a5dd (diff)
downloaddotfiles-dac08d6522270d4ad312efabdba02aff121af1e3.tar.gz
dotfiles-dac08d6522270d4ad312efabdba02aff121af1e3.tar.bz2
dotfiles-dac08d6522270d4ad312efabdba02aff121af1e3.zip
Add verbose status option
Diffstat (limited to 'dotfiles.py')
-rw-r--r--dotfiles.py66
1 files changed, 47 insertions, 19 deletions
diff --git a/dotfiles.py b/dotfiles.py
index 04b1394..460f5f3 100644
--- a/dotfiles.py
+++ b/dotfiles.py
@@ -119,7 +119,7 @@ def add(repo, files):
@cli.command()
-@click.option('-v', '--verbose', is_flag=True, help='Show dotfile state.')
+@click.option('-v', '--verbose', is_flag=True, help='Enable verbose output.')
@pass_repo
def list(repo, verbose):
"""Show the contents of a repository."""
@@ -142,33 +142,61 @@ def remove(repo, files):
Dotfile(filename, repo.target(filename)).remove()
+def show_status(dotfiles, state_info, color):
+ for dotfile in dotfiles:
+ try:
+ msg = '%s %s' % (state_info[dotfile.state]['char'], dotfile)
+ fg = state_info[dotfile.state]['color'] if color else None
+ click.secho(msg, fg=fg)
+ except KeyError:
+ continue
+
+
+def show_verbose_status(dotfiles, state_info, color):
+ errors = [d for d in dotfiles if d.state == 'error']
+ conflicts = [d for d in dotfiles if d.state == 'conflict']
+ missing = [d for d in dotfiles if d.state == 'missing']
+
+ def _show(dotfiles, state):
+ for dotfile in dotfiles:
+ click.secho(' %s: %s' % (state, dotfile),
+ fg=state_info[state]['color'] if color else None)
+
+ if errors:
+ click.echo('Dotfiles with no target:\n')
+ _show(errors, 'error')
+ click.echo()
+
+ if conflicts:
+ click.echo('Repository and home directory files are different:\n')
+ _show(conflicts, 'conflict')
+ click.echo()
+
+ if missing:
+ click.echo('Missing symlink in home directory:\n')
+ _show(missing, 'missing')
+ click.echo()
+
+
@cli.command()
-@click.option('-c', '--color', is_flag=True, help='Enable color.')
-@click.option('-s', '--short', is_flag=True, help='Show terse output.')
+@click.option('-c', '--color', is_flag=True, help='Enable color.')
+@click.option('-v', '--verbose', is_flag=True, help='Enable verbose output.')
@pass_repo
-def status(repo, color, short):
- """Show all dotifles in a non-OK state."""
+def status(repo, color, verbose):
+ """Show all dotfiles in a non-OK state."""
- states = {
+ state_info = {
'error': {'char': 'E', 'color': 'red'},
'conflict': {'char': '!', 'color': 'magenta'},
'missing': {'char': '?', 'color': 'yellow'},
}
- if not short:
- click.echo('long output not yet implemeted, using --short for now')
-
dotfiles = repo.contents()
- for dotfile in dotfiles:
- try:
- state_str = states[dotfile.state]['char']
- color_str = states[dotfile.state]['color']
- if color:
- click.secho('%s %s' % (state_str, dotfile), fg=color_str)
- else:
- click.echo('%s %s' % (state_str, dotfile))
- except KeyError:
- continue
+
+ if verbose:
+ show_verbose_status(dotfiles, state_info, color)
+ else:
+ show_status(dotfiles, state_info, color)
@cli.command()