Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit eb3a53d

Browse files
#52: omnibus improvements
* Colorizes and massively improves 'bak list' * Improve config and provide cli access * Restore .bakfiles to arbitrary locations
1 parent 2d0c77c commit eb3a53d

File tree

6 files changed

+513
-120
lines changed

6 files changed

+513
-120
lines changed

bak/__main__.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from bak import commands
88
from bak import BAK_VERSION as bak_version
9+
from bak.configuration import bak_cfg as cfg
910

1011

1112
def __print_help():
@@ -50,18 +51,21 @@ def bak():
5051
def _create(filename, version):
5152
create_bak_cmd(filename, version)
5253

54+
5355
@bak.command("create", hidden=True)
5456
@normalize_path()
5557
@click.option("--version", required=False, is_flag=True)
5658
@click.argument("filename", required=False, type=click.Path(exists=True))
5759
def create(filename, version):
5860
create_bak_cmd(filename, version)
5961

60-
# Ensures that 'bak --help' is printed if it doesn't get a filename
62+
63+
6164
def create_bak_cmd(filename, version):
6265
if version:
6366
click.echo(f"bak version {bak_version}")
6467
elif not filename:
68+
# Ensures that 'bak --help' is printed if it doesn't get a filename
6569
__print_help()
6670
else:
6771
filename = Path(filename).expanduser().resolve()
@@ -154,19 +158,46 @@ def bak_diff(filename, using):
154158

155159
@bak.command("list",
156160
help="List all .bakfiles, or a particular file's")
157-
@click.option("--relpaths",
161+
@click.option("--colors/--nocolors", "-c/-C",
162+
help="Colorize output",
163+
is_flag=True,
164+
default=cfg['bak_list_colors'] and not cfg['fast_mode'])
165+
@click.option("--relpaths", "--rel", "-r",
158166
help="Display relative paths instead of abspaths",
159167
required=False,
160168
is_flag=True,
161-
default=commands.bak_list_relpaths)
169+
default=commands.BAK_LIST_RELPATHS)
170+
@click.option("--compare", "--diff", "-d",
171+
help="Compare .bakfiles with current file, identify exact copies",
172+
required=False,
173+
is_flag=True,
174+
default=False)
162175
@click.argument("filename",
163176
required=False,
164177
type=click.Path(exists=True))
165178
@normalize_path()
166-
def bak_list(relpaths, filename):
179+
def bak_list(colors, relpaths, compare, filename):
167180
if filename:
168181
filename = Path(filename).expanduser().resolve()
169-
commands.show_bak_list(filename=filename or None, relative_paths=relpaths)
182+
commands.show_bak_list(filename=filename or None,
183+
relative_paths=relpaths, colors=colors, compare=compare)
184+
185+
186+
TAB = '\t'
187+
CFG_HELP_TEXT = '\b\nGet/set config values. Valid settings include:\n\n\t' + \
188+
f'\b\n{(TAB + cfg.newline).join(cfg.SETTABLE_VALUES)}' + \
189+
'\b\n\nNOTE: diff-exec\'s value should be enclosed in quotes, and' \
190+
'\nformatted like:\b\n\n\t\'diff %old %new\' \b\n\n(%old and %new will be substituted ' \
191+
'with the bakfile and the original file, respectively)'
192+
193+
194+
@bak.command("config",
195+
short_help="get/set config options", help=CFG_HELP_TEXT)
196+
@click.option("--get/--set", default=True)
197+
@click.argument("setting", required=True)
198+
@click.argument("value", required=False, nargs=-1, type=str)
199+
def bak_config(get, setting, value):
200+
commands.bak_config_command(get, setting, value)
170201

171202

172203
if __name__ == "__main__":

0 commit comments

Comments
 (0)