Skip to content

Commit 397fd72

Browse files
committed
Made subparser aliases compatible with python2
1 parent e9ce5a6 commit 397fd72

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

pythonforandroid/toolchain.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,54 +294,63 @@ def __init__(self):
294294
subparsers = parser.add_subparsers(dest='subparser_name',
295295
help='The command to run')
296296

297-
parser_recipes = subparsers.add_parser(
297+
def add_parser(subparsers, *args, **kwargs):
298+
'''
299+
argparse in python2 doesn't support the aliases option,
300+
so we just don't provide the aliases there.
301+
'''
302+
if 'aliases' in kwargs and sys.version_info.major < 3:
303+
kwargs.pop('aliases')
304+
return subparsers.add_parser(*args, **kwargs)
305+
306+
parser_recipes = add_parser(subparsers,
298307
'recipes',
299308
parents=[generic_parser],
300309
help='List the available recipes')
301310
parser_recipes.add_argument(
302311
"--compact", action="store_true", default=False,
303312
help="Produce a compact list suitable for scripting")
304313

305-
parser_bootstraps = subparsers.add_parser(
314+
parser_bootstraps = add_parser(subparsers,
306315
'bootstraps', help='List the available bootstraps',
307316
parents=[generic_parser])
308-
parser_clean_all = subparsers.add_parser(
317+
parser_clean_all = add_parser(subparsers,
309318
'clean_all', aliases=['clean-all'],
310319
help='Delete all builds, dists and caches',
311320
parents=[generic_parser])
312-
parser_clean_dists = subparsers.add_parser(
321+
parser_clean_dists = add_parser(subparsers,
313322
'clean_dists', aliases=['clean-dists'],
314323
help='Delete all dists',
315324
parents=[generic_parser])
316-
parser_clean_bootstrap_builds = subparsers.add_parser(
325+
parser_clean_bootstrap_builds = add_parser(subparsers,
317326
'clean_bootstrap_builds', aliases=['clean-bootstrap-builds'],
318327
help='Delete all bootstrap builds',
319328
parents=[generic_parser])
320-
parser_clean_builds = subparsers.add_parser(
329+
parser_clean_builds = add_parser(subparsers,
321330
'clean_builds', aliases=['clean-builds'],
322331
help='Delete all builds',
323332
parents=[generic_parser])
324333

325-
parser_clean_recipe_build = subparsers.add_parser(
334+
parser_clean_recipe_build = add_parser(subparsers,
326335
'clean_recipe_build', aliases=['clean-recipe-build'],
327336
help='Delete the build info for the given recipe',
328337
parents=[generic_parser])
329338
parser_clean_recipe_build.add_argument('recipe', help='The recipe name')
330339

331-
parser_clear_download_cache= subparsers.add_parser(
340+
parser_clear_download_cache= add_parser(subparsers,
332341
'clear_download_cache', aliases=['clear-download-cache'],
333342
help='Delete any cached recipe downloads',
334343
parents=[generic_parser])
335344

336-
parser_export_dist = subparsers.add_parser(
345+
parser_export_dist = add_parser(subparsers,
337346
'export_dist', aliases=['export-dist'],
338347
help='Copy the named dist to the given path',
339348
parents=[generic_parser])
340349
parser_export_dist.add_argument('output_dir', help=('The output dir to copy to'))
341350
parser_export_dist.add_argument('--symlink', action='store_true',
342351
help=('Symlink the dist instead of copying'))
343352

344-
parser_apk = subparsers.add_parser(
353+
parser_apk = add_parser(subparsers,
345354
'apk', help='Build an APK',
346355
parents=[generic_parser])
347356
parser_apk.add_argument('--release', dest='build_mode', action='store_const',
@@ -357,34 +366,34 @@ def __init__(self):
357366
parser_apk.add_argument('--signkeypw', dest='signkeypw', action='store', default=None,
358367
help='Password for key alias')
359368

360-
parser_create = subparsers.add_parser(
369+
parser_create = add_parser(subparsers,
361370
'create', help='Compile a set of requirements into a dist',
362371
parents=[generic_parser])
363-
parser_archs = subparsers.add_parser(
372+
parser_archs = add_parser(subparsers,
364373
'archs', help='List the available target architectures',
365374
parents=[generic_parser])
366-
parser_distributions = subparsers.add_parser(
375+
parser_distributions = add_parser(subparsers,
367376
'distributions', aliases=['dists'],
368377
help='List the currently available (compiled) dists',
369378
parents=[generic_parser])
370-
parser_delete_dist = subparsers.add_parser(
379+
parser_delete_dist = add_parser(subparsers,
371380
'delete_dist', aliases=['delete-dist'], help='Delete a compiled dist',
372381
parents=[generic_parser])
373382

374-
parser_sdk_tools = subparsers.add_parser(
383+
parser_sdk_tools = add_parser(subparsers,
375384
'sdk_tools', aliases=['sdk-tools'],
376385
help='Run the given binary from the SDK tools dis',
377386
parents=[generic_parser])
378387
parser_sdk_tools.add_argument(
379388
'tool', help=('The tool binary name to run'))
380389

381-
parser_adb = subparsers.add_parser(
390+
parser_adb = add_parser(subparsers,
382391
'adb', help='Run adb from the given SDK',
383392
parents=[generic_parser])
384-
parser_logcat = subparsers.add_parser(
393+
parser_logcat = add_parser(subparsers,
385394
'logcat', help='Run logcat from the given SDK',
386395
parents=[generic_parser])
387-
parser_build_status = subparsers.add_parser(
396+
parser_build_status = add_parser(subparsers,
388397
'build_status', aliases=['build-status'],
389398
help='Print some debug information about current built components',
390399
parents=[generic_parser])

0 commit comments

Comments
 (0)