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

Commit b484b07

Browse files
Merge pull request #63 from bakfile/unstable
2 parents 2d0c77c + 544e6f8 commit b484b07

File tree

8 files changed

+520
-127
lines changed

8 files changed

+520
-127
lines changed

bak/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BAK_VERSION = "0.1.1a1"
1+
BAK_VERSION = "0.2.0a1"

bak/__main__.py

Lines changed: 41 additions & 10 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()
@@ -126,17 +130,17 @@ def bak_print(filename, using):
126130
commands.bak_print_cmd(filename, using)
127131

128132

129-
@bak.command("get-bak",
133+
@bak.command("where",
130134
help="Outputs the real path of a .bakfile. "
131135
"Useful for piping, and not much else.",
132136
short_help="Output the real path of a .bakfile")
133-
@click.argument("to_where_you_once_belonged",
137+
@click.argument("filename",
134138
required=True,
135-
type=click.Path(exists=True))
139+
type=click.Path())
136140
@normalize_path()
137-
def bak_get(to_where_you_once_belonged):
141+
def bak_get(filename):
138142
to_where_you_once_belonged = Path(
139-
to_where_you_once_belonged).expanduser().resolve()
143+
filename).expanduser().resolve()
140144
commands.bak_getfile_cmd(to_where_you_once_belonged)
141145

142146

@@ -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)