|
6 | 6 |
|
7 | 7 | from bak import commands |
8 | 8 | from bak import BAK_VERSION as bak_version |
| 9 | +from bak.configuration import bak_cfg as cfg |
9 | 10 |
|
10 | 11 |
|
11 | 12 | def __print_help(): |
@@ -50,18 +51,21 @@ def bak(): |
50 | 51 | def _create(filename, version): |
51 | 52 | create_bak_cmd(filename, version) |
52 | 53 |
|
| 54 | + |
53 | 55 | @bak.command("create", hidden=True) |
54 | 56 | @normalize_path() |
55 | 57 | @click.option("--version", required=False, is_flag=True) |
56 | 58 | @click.argument("filename", required=False, type=click.Path(exists=True)) |
57 | 59 | def create(filename, version): |
58 | 60 | create_bak_cmd(filename, version) |
59 | 61 |
|
60 | | -# Ensures that 'bak --help' is printed if it doesn't get a filename |
| 62 | + |
| 63 | + |
61 | 64 | def create_bak_cmd(filename, version): |
62 | 65 | if version: |
63 | 66 | click.echo(f"bak version {bak_version}") |
64 | 67 | elif not filename: |
| 68 | + # Ensures that 'bak --help' is printed if it doesn't get a filename |
65 | 69 | __print_help() |
66 | 70 | else: |
67 | 71 | filename = Path(filename).expanduser().resolve() |
@@ -154,19 +158,46 @@ def bak_diff(filename, using): |
154 | 158 |
|
155 | 159 | @bak.command("list", |
156 | 160 | 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", |
158 | 166 | help="Display relative paths instead of abspaths", |
159 | 167 | required=False, |
160 | 168 | 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) |
162 | 175 | @click.argument("filename", |
163 | 176 | required=False, |
164 | 177 | type=click.Path(exists=True)) |
165 | 178 | @normalize_path() |
166 | | -def bak_list(relpaths, filename): |
| 179 | +def bak_list(colors, relpaths, compare, filename): |
167 | 180 | if filename: |
168 | 181 | 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) |
170 | 201 |
|
171 | 202 |
|
172 | 203 | if __name__ == "__main__": |
|
0 commit comments