fix: escape file names in CLI messages
This commit is contained in:
parent
78528abd3a
commit
d879c6f871
2 changed files with 20 additions and 13 deletions
|
|
@ -160,15 +160,15 @@ def main():
|
|||
if args.command in ['add', 'a']:
|
||||
if args.file and args.context:
|
||||
context = orvani.add(args.file, *args.context)
|
||||
console.print(f':label: Entry {nice_context(context)}successfully added to file [strong]{args.file}[/strong].')
|
||||
console.print(f':label: Entry {nice_context(context)}successfully added to file [strong]{escape(str(args.file))}[/strong].')
|
||||
|
||||
elif args.command in ['remove', 'r']:
|
||||
if args.file:
|
||||
context = orvani.remove(args.file, *args.context)
|
||||
if context is None:
|
||||
console.print(f':wastebasket: All entries successfully removed from file [strong]{args.file}[/strong].')
|
||||
console.print(f':wastebasket: All entries successfully removed from file [strong]{escape(str(args.file))}[/strong].')
|
||||
else:
|
||||
console.print(f':wastebasket: Entry {nice_context(context)}successfully removed from file [strong]{args.file}[/strong].')
|
||||
console.print(f':wastebasket: Entry {nice_context(context)}successfully removed from file [strong]{escape(str(args.file))}[/strong].')
|
||||
|
||||
elif args.command in ['list', 'ls', 'l']:
|
||||
query = [args.file] + args.context
|
||||
|
|
@ -186,16 +186,16 @@ def main():
|
|||
copy = args.command in ['copy', 'cp']
|
||||
transfer = orvani.copy if copy else orvani.move
|
||||
context = transfer(args.file, args.context[0], with_file=args.file_operation)
|
||||
console.print(f':dancers: File [strong]{args.file}[/strong] with entry {nice_context(context)}successfully {"copied" if copy else "moved"} to [strong]{args.context[0]}[/strong]')
|
||||
console.print(f':dancers: File [strong]{escape(str(args.file))}[/strong] with entry {nice_context(context)}successfully {"copied" if copy else "moved"} to [strong]{escape(str(args.context[0]))}[/strong]')
|
||||
|
||||
elif args.command in ['del', 'rm']:
|
||||
if args.file:
|
||||
context_file = orvani.delete(args.file, with_file=args.file_operation)
|
||||
status = f':wastebasket: Entry for [strong]{args.file}[/strong] successfully removed.'
|
||||
status = f':wastebasket: Entry for [strong]{escape(str(args.file))}[/strong] successfully removed.'
|
||||
if args.file_operation:
|
||||
status += f'\n:wastebasket: File [strong]{args.file}[/strong] successfully deleted.'
|
||||
status += f'\n:wastebasket: File [strong]{escape(str(args.file))}[/strong] successfully deleted.'
|
||||
if context_file:
|
||||
status += f'\n:wastebasket: File [strong]{context_file}[/strong] automatically deleted.'
|
||||
status += f'\n:wastebasket: File [strong]{escape(str(context_file))}[/strong] automatically deleted.'
|
||||
console.print(status)
|
||||
|
||||
|
||||
|
|
@ -209,11 +209,11 @@ def main():
|
|||
context_file = target / CONTEXT_FILE
|
||||
if context_file.exists():
|
||||
context_file.unlink(missing_ok=True)
|
||||
console.print(f":wastebasket: File [strong]{context_file}[/strong] successfully purged.")
|
||||
console.print(f":wastebasket: File [strong]{escape(str(context_file))}[/strong] successfully purged.")
|
||||
cache_file = target / CACHE_FILE
|
||||
if cache_file.exists():
|
||||
cache_file.unlink(missing_ok=True)
|
||||
console.print(f":wastebasket: File [strong]{cache_file}[/strong] successfully purged.")
|
||||
console.print(f":wastebasket: File [strong]{escape(str(cache_file))}[/strong] successfully purged.")
|
||||
|
||||
if not args.file:
|
||||
args.file = '.'
|
||||
|
|
@ -223,20 +223,20 @@ def main():
|
|||
elif args.command in ['clean', 'c']:
|
||||
count = orvani.clean(args.file or '', args.recursive)
|
||||
sub = ' and subdirectories' if args.recursive else ''
|
||||
console.print(f':broom: {count} entries cleaned from [strong]{args.file or "."}[/strong]{sub}')
|
||||
console.print(f':broom: {count} entries cleaned from [strong]{escape(str(args.file or "."))}[/strong]{sub}')
|
||||
|
||||
elif args.command in ['write', 'w']:
|
||||
if args.file and args.context:
|
||||
context = orvani.write_metadata(args.context[0], args.file)
|
||||
console.print(f':floppy_disk: Metadata {nice_context(context)}successfully written to file [strong]{args.context[0]}[/strong].')
|
||||
console.print(f':floppy_disk: Metadata {nice_context(context)}successfully written to file [strong]{escape(str(args.context[0]))}[/strong].')
|
||||
|
||||
elif args.command in ['export', 'e']:
|
||||
filename = orvani.export(args.file)
|
||||
console.print(f':floppy_disk: All entries successfully written to file [strong]{filename}[/strong].')
|
||||
console.print(f':floppy_disk: All entries successfully written to file [strong]{escape(str(filename))}[/strong].')
|
||||
|
||||
elif args.command in ['import', 'i']:
|
||||
count = orvani.import_file(args.file)
|
||||
console.print(f':inbox_tray: [strong]{count}[/strong] entries successfully imported from file [strong]{args.file or "context.txt"}[/strong].')
|
||||
console.print(f':inbox_tray: [strong]{count}[/strong] entries successfully imported from file [strong]{escape(str(args.file or "context.txt"))}[/strong].')
|
||||
|
||||
elif args.command in ['scan', 's']:
|
||||
orvani.scan(args.file or '', args.recursive)
|
||||
|
|
|
|||
|
|
@ -179,3 +179,10 @@ def test_cmd_list_shows_square_brackets(cwd, monkeypatch, capsys):
|
|||
main()
|
||||
out = capsys.readouterr().out
|
||||
assert 'a [demo].mp3' in out and '[with]' in out
|
||||
|
||||
|
||||
def test_cmd_messages_show_square_brackets_in_file_names(cwd, monkeypatch, capsys):
|
||||
(cwd / 'a [demo].mp3').touch()
|
||||
monkeypatch.setattr(sys, 'argv', ['otag', 'a', 'a [demo].mp3', '#lofi'])
|
||||
main()
|
||||
assert 'a [demo].mp3' in capsys.readouterr().out
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue