diff options
author | Jon Bernard <jbernard@tuxion.com> | 2016-01-04 13:18:32 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2016-01-04 13:18:32 -0500 |
commit | dac08d6522270d4ad312efabdba02aff121af1e3 (patch) | |
tree | b2adac7e8fc381f5241e83ad4f9f982500330ed1 | |
parent | ce3e697f8da61afd5a8fab377983d69abb20a5dd (diff) | |
download | dotfiles-dac08d6522270d4ad312efabdba02aff121af1e3.tar.gz dotfiles-dac08d6522270d4ad312efabdba02aff121af1e3.tar.bz2 dotfiles-dac08d6522270d4ad312efabdba02aff121af1e3.zip |
Add verbose status option
-rw-r--r-- | dotfiles.py | 66 | ||||
-rw-r--r-- | setup.py | 2 |
2 files changed, 48 insertions, 20 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() @@ -12,7 +12,7 @@ setup( open('LICENSE.rst').read() + '\n\n' + open('HISTORY.rst').read()), license='ISC', - py_modules=['dotifles'], + py_modules=['dotfiles'], install_requires=[ 'click', 'py', |