refactor: deprecate + rename command print -> info
This commit is contained in:
@@ -31,7 +31,7 @@ positional arguments:
|
||||
extract (e) Read and extract contents of icns file(s).
|
||||
compose (c) Create new icns file from provided image files.
|
||||
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.
|
||||
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
|
||||
|
||||
# print
|
||||
icnsutil p Existing.icns
|
||||
icnsutil i Existing.icns
|
||||
|
||||
# verify valid format
|
||||
icnsutil t Existing.icns
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
'''
|
||||
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 .ArgbImage import ArgbImage, PIL_ENABLED
|
||||
|
||||
@@ -161,20 +161,20 @@ def main() -> None:
|
||||
parser.set_defaults(func=lambda _: parser.print_help(sys.stdout))
|
||||
parser.add_argument(
|
||||
'-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
|
||||
def add_command(
|
||||
name: str, alias: str, fn: Callable[[ArgParams], None]
|
||||
name: str, aliases: List[str], fn: Callable[[ArgParams], None]
|
||||
) -> ArgumentParser:
|
||||
desc = fn.__doc__ or ''
|
||||
cmd = sub_parser.add_parser(name, aliases=[alias],
|
||||
help=desc, description=desc.strip())
|
||||
cmd = sub_parser.add_parser(name, aliases=aliases, help=desc,
|
||||
description=desc.strip())
|
||||
cmd.set_defaults(func=fn)
|
||||
return cmd
|
||||
|
||||
# Extract
|
||||
cmd = add_command('extract', 'e', cli_extract)
|
||||
cmd = add_command('extract', ['e'], cli_extract)
|
||||
cmd.add_argument('-r', '--recursive', action='store_true',
|
||||
help='extract nested icns files as well')
|
||||
cmd.add_argument('-o', '--export-dir', type=PathExist('d'),
|
||||
@@ -189,7 +189,7 @@ def main() -> None:
|
||||
metavar='FILE', help='One or more .icns files')
|
||||
|
||||
# Compose
|
||||
cmd = add_command('compose', 'c', cli_compose)
|
||||
cmd = add_command('compose', ['c'], cli_compose)
|
||||
cmd.add_argument('-f', '--force', action='store_true',
|
||||
help='Force overwrite output file')
|
||||
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.''')
|
||||
|
||||
# Update
|
||||
cmd = add_command('update', 'u', cli_update)
|
||||
cmd = add_command('update', ['u'], cli_update)
|
||||
cmd.add_argument('file', type=PathExist('f', stdin=True),
|
||||
metavar='FILE', help='The icns file to be updated.')
|
||||
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"'
|
||||
|
||||
# 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',
|
||||
help='print all keys with offsets and sizes')
|
||||
cmd.add_argument('-q', '--quiet', action='store_true',
|
||||
@@ -229,14 +229,14 @@ def main() -> None:
|
||||
metavar='FILE', help='One or more .icns files.')
|
||||
|
||||
# Verify
|
||||
cmd = add_command('test', 't', cli_verify)
|
||||
cmd = add_command('test', ['t'], cli_verify)
|
||||
cmd.add_argument('-q', '--quiet', action='store_true',
|
||||
help='do not print OK results')
|
||||
cmd.add_argument('file', type=PathExist('f', stdin=True), nargs='+',
|
||||
metavar='FILE', help='One or more .icns files.')
|
||||
|
||||
# Convert
|
||||
cmd = add_command('convert', 'img', cli_convert)
|
||||
cmd = add_command('convert', ['img'], cli_convert)
|
||||
cmd.add_argument('--raw', action='store_true',
|
||||
help='no post-processing. Do not prepend it32 header.')
|
||||
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.')
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ class TestCLI_update(unittest.TestCase):
|
||||
|
||||
class TestCLI_print(unittest.TestCase):
|
||||
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',
|
||||
b's8mk', b'it32', b't8mk', b'16x16', b'32x32', b'128x128']:
|
||||
self.assertTrue(x in ret)
|
||||
@@ -209,11 +209,11 @@ class TestCLI_print(unittest.TestCase):
|
||||
self.assertFalse(b'offset' in ret)
|
||||
|
||||
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)
|
||||
|
||||
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']:
|
||||
self.assertTrue(x in ret)
|
||||
self.assertFalse(b'offset' in ret)
|
||||
|
||||
Reference in New Issue
Block a user