66
77from bak import commands
88from bak import BAK_VERSION as bak_version
9+ from bak .configuration import bak_cfg as cfg
910
1011
1112def __print_help ():
@@ -50,18 +51,21 @@ def bak():
5051def _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 ))
5759def 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+
6164def 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 \n Get/set config values. Valid settings include:\n \n \t ' + \
188+ f'\b \n { (TAB + cfg .newline ).join (cfg .SETTABLE_VALUES )} ' + \
189+ '\b \n \n NOTE: diff-exec\' s value should be enclosed in quotes, and' \
190+ '\n formatted 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
172203if __name__ == "__main__" :
0 commit comments