feat: add --quiet option to print command
This commit is contained in:
@@ -116,10 +116,10 @@ class IcnsFile:
|
||||
txt += ', ' + ext + ': ' + iType.filename(size_only=True)
|
||||
except NotImplementedError:
|
||||
txt += ': UNKNOWN TYPE: ' + str(ext or data[:6])
|
||||
return txt[len(os.linesep):] + os.linesep
|
||||
return txt[len(os.linesep):]
|
||||
# if file is not an icns file
|
||||
except RawData.ParserError as e:
|
||||
return ' ' * indent + str(e) + os.linesep
|
||||
return ' ' * indent + str(e)
|
||||
|
||||
def __init__(self, file: Optional[str] = None) -> None:
|
||||
''' Read .icns file and load bundled media files into memory. '''
|
||||
|
||||
@@ -78,9 +78,13 @@ def cli_update(args: ArgParams) -> None:
|
||||
|
||||
def cli_print(args: ArgParams) -> None:
|
||||
''' Print contents of icns file(s). '''
|
||||
indent = 0 if args.quiet else 2
|
||||
for fname in enum_with_stdin(args.file):
|
||||
print('File:', fname)
|
||||
print(IcnsFile.description(fname, verbose=args.verbose, indent=2))
|
||||
if not args.quiet:
|
||||
print('File:', fname)
|
||||
print(IcnsFile.description(fname, verbose=args.verbose, indent=indent))
|
||||
if not args.quiet:
|
||||
print()
|
||||
|
||||
|
||||
def cli_verify(args: ArgParams) -> None:
|
||||
@@ -219,6 +223,8 @@ def main() -> None:
|
||||
cmd = add_command('print', 'p', cli_print)
|
||||
cmd.add_argument('-v', '--verbose', action='store_true',
|
||||
help='print all keys with offsets and sizes')
|
||||
cmd.add_argument('-q', '--quiet', action='store_true',
|
||||
help='do not print filename and indentation')
|
||||
cmd.add_argument('file', type=PathExist('f', stdin=True), nargs='+',
|
||||
metavar='FILE', help='One or more .icns files.')
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ is32: 705 bytes, rgb: 16x16
|
||||
s8mk: 256 bytes, mask: 16x16
|
||||
it32: 14005 bytes, rgb: 128x128
|
||||
t8mk: 16384 bytes, mask: 128x128
|
||||
'''.lstrip().replace('\n', os.linesep))
|
||||
'''.strip().replace('\n', os.linesep))
|
||||
str = IcnsFile.description('selected.icns', verbose=True, indent=0)
|
||||
self.assertEqual(str, '''
|
||||
info: 314 bytes, offset: 8, plist: info
|
||||
@@ -259,7 +259,7 @@ ic05: 690 bytes, offset: 5148, argb: 32x32
|
||||
icsB: 1001 bytes, offset: 5846, png: 18x18@2x
|
||||
ic11: 1056 bytes, offset: 6855, png: 16x16@2x
|
||||
slct: 7660 bytes, offset: 7919, icns: selected
|
||||
'''.lstrip().replace('\n', os.linesep))
|
||||
'''.strip().replace('\n', os.linesep))
|
||||
|
||||
|
||||
class TestIcnsType(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user