refactor: deprecate + rename command print -> info

This commit is contained in:
relikd
2023-03-08 00:48:40 +01:00
parent 824616403e
commit 176b675316
4 changed files with 19 additions and 16 deletions

View File

@@ -31,7 +31,7 @@ positional arguments:
extract (e) Read and extract contents of icns file(s). extract (e) Read and extract contents of icns file(s).
compose (c) Create new icns file from provided image files. compose (c) Create new icns file from provided image files.
update (u) Update existing icns file by inserting or removing media entries. update (u) Update existing icns file by inserting or removing media entries.
print (p) Print contents of icns file(s). info (i) Print contents of icns file(s).
test (t) Test if icns file is valid. test (t) Test if icns file is valid.
convert (img) Convert images between PNG, ARGB, or RGB + alpha mask. convert (img) Convert images between PNG, ARGB, or RGB + alpha mask.
``` ```
@@ -52,7 +52,7 @@ icnsutil u Existing.icns -set is32=16.rgb dark="dark icon.icns"
icnsutil u Existing.icns -rm dark -set ic04=16.argb -o Updated.icns icnsutil u Existing.icns -rm dark -set ic04=16.argb -o Updated.icns
# print # print
icnsutil p Existing.icns icnsutil i Existing.icns
# verify valid format # verify valid format
icnsutil t Existing.icns icnsutil t Existing.icns

View File

@@ -2,7 +2,7 @@
''' '''
A fully-featured python library to handle reading and writing icns files. A fully-featured python library to handle reading and writing icns files.
''' '''
__version__ = '1.0.1' __version__ = '1.1.0'
from .IcnsFile import IcnsFile from .IcnsFile import IcnsFile
from .ArgbImage import ArgbImage, PIL_ENABLED from .ArgbImage import ArgbImage, PIL_ENABLED

View File

@@ -161,20 +161,20 @@ def main() -> None:
parser.set_defaults(func=lambda _: parser.print_help(sys.stdout)) parser.set_defaults(func=lambda _: parser.print_help(sys.stdout))
parser.add_argument( parser.add_argument(
'-v', '--version', action='version', version='icnsutil ' + __version__) '-v', '--version', action='version', version='icnsutil ' + __version__)
sub_parser = parser.add_subparsers(metavar='command') sub_parser = parser.add_subparsers(metavar='command', dest='command')
# helper method # helper method
def add_command( def add_command(
name: str, alias: str, fn: Callable[[ArgParams], None] name: str, aliases: List[str], fn: Callable[[ArgParams], None]
) -> ArgumentParser: ) -> ArgumentParser:
desc = fn.__doc__ or '' desc = fn.__doc__ or ''
cmd = sub_parser.add_parser(name, aliases=[alias], cmd = sub_parser.add_parser(name, aliases=aliases, help=desc,
help=desc, description=desc.strip()) description=desc.strip())
cmd.set_defaults(func=fn) cmd.set_defaults(func=fn)
return cmd return cmd
# Extract # Extract
cmd = add_command('extract', 'e', cli_extract) cmd = add_command('extract', ['e'], cli_extract)
cmd.add_argument('-r', '--recursive', action='store_true', cmd.add_argument('-r', '--recursive', action='store_true',
help='extract nested icns files as well') help='extract nested icns files as well')
cmd.add_argument('-o', '--export-dir', type=PathExist('d'), cmd.add_argument('-o', '--export-dir', type=PathExist('d'),
@@ -189,7 +189,7 @@ def main() -> None:
metavar='FILE', help='One or more .icns files') metavar='FILE', help='One or more .icns files')
# Compose # Compose
cmd = add_command('compose', 'c', cli_compose) cmd = add_command('compose', ['c'], cli_compose)
cmd.add_argument('-f', '--force', action='store_true', cmd.add_argument('-f', '--force', action='store_true',
help='Force overwrite output file') help='Force overwrite output file')
cmd.add_argument('--toc', action='store_true', help=''' cmd.add_argument('--toc', action='store_true', help='''
@@ -207,7 +207,7 @@ def main() -> None:
the file is automatically assigned to an icns file field.''') the file is automatically assigned to an icns file field.''')
# Update # Update
cmd = add_command('update', 'u', cli_update) cmd = add_command('update', ['u'], cli_update)
cmd.add_argument('file', type=PathExist('f', stdin=True), cmd.add_argument('file', type=PathExist('f', stdin=True),
metavar='FILE', help='The icns file to be updated.') metavar='FILE', help='The icns file to be updated.')
cmd.add_argument('-o', '--output', type=str, metavar='OUT_FILE', cmd.add_argument('-o', '--output', type=str, metavar='OUT_FILE',
@@ -220,7 +220,7 @@ def main() -> None:
cmd.epilog = 'KEY supports names like "dark", "selected", and "template"' cmd.epilog = 'KEY supports names like "dark", "selected", and "template"'
# Print # Print
cmd = add_command('print', 'p', cli_print) cmd = add_command('info', ['i', 'p', 'print'], cli_print)
cmd.add_argument('-v', '--verbose', action='store_true', cmd.add_argument('-v', '--verbose', action='store_true',
help='print all keys with offsets and sizes') help='print all keys with offsets and sizes')
cmd.add_argument('-q', '--quiet', action='store_true', cmd.add_argument('-q', '--quiet', action='store_true',
@@ -229,14 +229,14 @@ def main() -> None:
metavar='FILE', help='One or more .icns files.') metavar='FILE', help='One or more .icns files.')
# Verify # Verify
cmd = add_command('test', 't', cli_verify) cmd = add_command('test', ['t'], cli_verify)
cmd.add_argument('-q', '--quiet', action='store_true', cmd.add_argument('-q', '--quiet', action='store_true',
help='do not print OK results') help='do not print OK results')
cmd.add_argument('file', type=PathExist('f', stdin=True), nargs='+', cmd.add_argument('file', type=PathExist('f', stdin=True), nargs='+',
metavar='FILE', help='One or more .icns files.') metavar='FILE', help='One or more .icns files.')
# Convert # Convert
cmd = add_command('convert', 'img', cli_convert) cmd = add_command('convert', ['img'], cli_convert)
cmd.add_argument('--raw', action='store_true', cmd.add_argument('--raw', action='store_true',
help='no post-processing. Do not prepend it32 header.') help='no post-processing. Do not prepend it32 header.')
cmd.add_argument('target', type=str, metavar='destination', cmd.add_argument('target', type=str, metavar='destination',
@@ -247,6 +247,9 @@ def main() -> None:
help='Alpha mask. If set, assume src is RGB image.') help='Alpha mask. If set, assume src is RGB image.')
args = parser.parse_args() args = parser.parse_args()
if args.command in ['p', 'print']:
print('{1}WARNING: command "{0}" is deprecated, use info instead.{1}'
.format(args.command, os.linesep), file=sys.stderr)
args.func(args) args.func(args)

View File

@@ -200,7 +200,7 @@ class TestCLI_update(unittest.TestCase):
class TestCLI_print(unittest.TestCase): class TestCLI_print(unittest.TestCase):
def test_single(self): def test_single(self):
ret = run_cli(['p', 'rgb.icns']).stdout ret = run_cli(['i', 'rgb.icns']).stdout
for x in [b'rgb.icns', b'ICN#', b'il32', b'l8mk', b'ics#', b'is32', for x in [b'rgb.icns', b'ICN#', b'il32', b'l8mk', b'ics#', b'is32',
b's8mk', b'it32', b't8mk', b'16x16', b'32x32', b'128x128']: b's8mk', b'it32', b't8mk', b'16x16', b'32x32', b'128x128']:
self.assertTrue(x in ret) self.assertTrue(x in ret)
@@ -209,11 +209,11 @@ class TestCLI_print(unittest.TestCase):
self.assertFalse(b'offset' in ret) self.assertFalse(b'offset' in ret)
def test_verbose(self): def test_verbose(self):
ret = run_cli(['p', '-v', 'rgb.icns']).stdout ret = run_cli(['i', '-v', 'rgb.icns']).stdout
self.assertTrue(b'offset' in ret) self.assertTrue(b'offset' in ret)
def test_multiple(self): def test_multiple(self):
ret = run_cli(['p', 'rgb.icns', 'icp4rgb.icns']).stdout ret = run_cli(['i', 'rgb.icns', 'icp4rgb.icns']).stdout
for x in [b'rgb.icns', b'icp4rgb.icns', b'icp4', b'icp5']: for x in [b'rgb.icns', b'icp4rgb.icns', b'icp4', b'icp5']:
self.assertTrue(x in ret) self.assertTrue(x in ret)
self.assertFalse(b'offset' in ret) self.assertFalse(b'offset' in ret)