aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-04 16:23:44 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-04 16:28:28 -0500
commit6735cda88aac20d21aecd239927311f07ef4f7f2 (patch)
treeabc900a6e962144a9a633d46840faefdc4cc8cbd
parent87fa2782267170afe0812c6a98ec21b3b1631ab7 (diff)
downloaddotfiles-6735cda88aac20d21aecd239927311f07ef4f7f2.tar.gz
dotfiles-6735cda88aac20d21aecd239927311f07ef4f7f2.tar.bz2
dotfiles-6735cda88aac20d21aecd239927311f07ef4f7f2.zip
Merge list into status and remove verbose
-rw-r--r--dotfiles.py104
-rw-r--r--test_dotfiles.py36
2 files changed, 31 insertions, 109 deletions
diff --git a/dotfiles.py b/dotfiles.py
index 11c62d1..af35d13 100644
--- a/dotfiles.py
+++ b/dotfiles.py
@@ -115,22 +115,9 @@ def cli(ctx, home_directory, repository):
def add(repo, files):
"""Add dotfiles to a repository."""
for filename in files:
- Dotfile(filename, repo.target(filename)).add()
-
-
-@cli.command()
-@click.option('-v', '--verbose', is_flag=True, help='Enable verbose output.')
-@pass_repo
-def list(repo, verbose):
- """Show the contents of a repository."""
- dotfiles = repo.contents()
- if not dotfiles:
- click.echo('[no dotfiles found]')
- for dotfile in dotfiles:
- if (verbose):
- click.echo('%-18s (%s)' % (dotfile, dotfile.state))
- else:
- click.echo('%s' % dotfile)
+ filename = py.path.local(filename)
+ click.echo('Dotfile(%s, %s).add()' % (
+ filename, repo.expected_name(filename)))
@cli.command()
@@ -139,72 +126,39 @@ def list(repo, verbose):
def remove(repo, files):
"""Remove dotfiles from a repository."""
for filename in 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']
- missing = [d for d in dotfiles if d.state == 'missing']
- conflicts = [d for d in dotfiles if d.state == 'conflict']
-
- def _show(dotfiles, state, color):
- for dotfile in dotfiles:
- click.secho(' %s: %s' % (state, dotfile), fg=color)
-
- if errors:
- click.echo('Dotfiles with no target:\n')
- _show(errors, 'error',
- state_info['error']['color'] if color else None)
- click.echo()
-
- if conflicts:
- click.echo('Repository and home directory files are different:\n')
- _show(conflicts, 'conflict',
- state_info['conflict']['color'] if color else None)
- click.echo()
-
- if missing:
- click.echo('Missing symlink in home directory:\n')
- _show(missing, 'missing',
- state_info['missing']['color'] if color else None)
- click.echo()
-
- total = len(errors) + len(conflicts) + len(missing)
- click.echo("%s dotfile%s need%s attention" %
- (total, 's' if total > 1 else '', '' if total > 1 else 's'))
+ filename = py.path.local(filename)
+ click.echo('Dotfile(%s, %s).remove()' % (
+ filename, repo.expected_name(filename)))
@cli.command()
-@click.option('-c', '--color', is_flag=True, help='Enable color.')
-@click.option('-v', '--verbose', is_flag=True, help='Enable verbose output.')
+@click.option('-a', '--all', is_flag=True, help='Show all dotfiles.')
+@click.option('-c', '--color', is_flag=True, help='Enable color output.')
@pass_repo
-def status(repo, color, verbose):
+def status(repo, all, color):
"""Show all dotfiles in a non-OK state."""
state_info = {
- 'error': {'char': 'E', 'color': 'red'},
- 'conflict': {'char': '!', 'color': 'magenta'},
- 'missing': {'char': '?', 'color': 'yellow'},
+ 'error': {'char': 'E', 'color': None},
+ 'conflict': {'char': '!', 'color': None},
+ 'missing': {'char': '?', 'color': None},
}
- dotfiles = repo.contents()
- if not dotfiles:
- return
+ if all:
+ state_info['ok'] = {'char': ' ', 'color': None}
- if verbose:
- show_verbose_status(dotfiles, state_info, color)
- else:
- show_status(dotfiles, state_info, color)
+ if color:
+ state_info['error']['color'] = 'red'
+ state_info['conflict']['color'] = 'magenta'
+ state_info['missing']['color'] = 'yellow'
+
+ for dotfile in repo.contents():
+ try:
+ char = state_info[dotfile.state]['char']
+ fg = state_info[dotfile.state]['color']
+ click.secho('%c %s' % (char, dotfile), fg=fg)
+ except KeyError:
+ continue
@cli.command()
@@ -213,9 +167,7 @@ def status(repo, color, verbose):
def sync(repo, files):
"""Create any missing symlinks."""
for filename in files:
- repo.sync(filename)
-
- # TODO: path need not exist...
+ click.echo('Dotfile(%s).sync()' % filename)
@cli.command()
@@ -224,4 +176,4 @@ def sync(repo, files):
def unsync(repo, files):
"""Remove existing symlinks."""
for filename in files:
- repo.unsync(filename)
+ click.echo('Dotfile(%s).unsync()' % filename)
diff --git a/test_dotfiles.py b/test_dotfiles.py
index 7f8c4cd..e5bdda2 100644
--- a/test_dotfiles.py
+++ b/test_dotfiles.py
@@ -6,42 +6,12 @@ from dotfiles import Repository, Dotfile, cli
class TestCli(object):
- def test_list_empty(self, runner, repo, home):
+ def test_status(self, runner, repo, home):
result = runner.invoke(cli, ['--home-directory', str(home),
'--repository', str(repo),
- 'list'])
+ 'status'])
assert not result.exception
- assert result.output == '[no dotfiles found]\n'
-
- def test_list(self, runner, repo, home):
- repo.ensure('foo')
- repo.ensure('bar')
- repo.ensure('baz')
- result = runner.invoke(cli, ['--home-directory', str(home),
- '--repository', str(repo),
- 'list'])
- assert not result.exception
- assert result.output == ('.bar\n'
- '.baz\n'
- '.foo\n')
-
- def test_list_verbose(self, runner, repo, home):
- repo.ensure('baz')
- repo.ensure('foo')
- home.ensure('.foo')
- home.join('.bar').mksymlinkto(repo.ensure('bar'))
-
- result = runner.invoke(cli, ['--home-directory', str(home),
- '--repository', str(repo),
- 'list', '--verbose'])
- assert not result.exception
- assert result.output == (
- '.bar (ok)\n'
- '.baz (missing)\n'
- '.foo (conflict)\n')
-
- def test_staus(self):
- pass
+ assert result.output == ''
class TestRepository(object):