@@ -175,6 +175,31 @@ def shprint(command, *args, **kwargs):
175
175
# exit(1)
176
176
177
177
178
+ def add_boolean_option (parser , names , no_names = None ,
179
+ default = True , dest = None , description = None ):
180
+ group = parser .add_argument_group (description = description )
181
+ if not isinstance (names , (list ,tuple )):
182
+ names = [names ]
183
+ if dest is None :
184
+ dest = names [0 ].strip ("-" ).replace ("-" ,"_" )
185
+ def add_dashes (x ):
186
+ return x if x .startswith ("-" ) else "--" + x
187
+ opts = [add_dashes (x ) for x in names ]
188
+ group .add_argument (
189
+ * opts , help = ("(this is the default)" if default else None ),
190
+ dest = dest , action = 'store_true' )
191
+ if no_names is None :
192
+ def add_no (x ):
193
+ x = x .lstrip ("-" )
194
+ return ("no_" + x ) if "_" in x else ("no-" + x )
195
+ no_names = [add_no (x ) for x in names ]
196
+ opts = [add_dashes (x ) for x in no_names ]
197
+ group .add_argument (
198
+ * opts , help = (None if default else "(this is the default)" ),
199
+ dest = dest , action = 'store_false' )
200
+ parser .set_defaults (** {dest :default })
201
+
202
+
178
203
def require_prebuilt_dist (func ):
179
204
'''Decorator for ToolchainCL methods. If present, the method will
180
205
automatically make sure a dist has been built before continuing
@@ -2513,23 +2538,32 @@ def __init__(self):
2513
2538
'--requirements' ,
2514
2539
help = 'Dependencies of your app, should be recipe names or Python modules' ,
2515
2540
default = '' )
2541
+
2542
+ add_boolean_option (
2543
+ parser , ["allow-download" , "allow_download" ],
2544
+ default = False ,
2545
+ description = 'Whether to allow binary dist download:' )
2546
+
2547
+ add_boolean_option (
2548
+ parser , ["allow-build" , "allow_build" ],
2549
+ default = True ,
2550
+ description = 'Whether to allow compilation of a new distribution:' )
2551
+
2552
+ add_boolean_option (
2553
+ parser , ["force-build" , "force_build" ],
2554
+ default = False ,
2555
+ description = 'Whether to force compilation of a new distribution:' )
2556
+
2516
2557
parser .add_argument (
2517
- '--allow_download' , help = 'Allow binary dist download.' ,
2518
- default = False , type = bool )
2519
- parser .add_argument (
2520
- '--allow_build' , help = 'Allow compilation of a new distribution.' ,
2521
- default = True , type = bool )
2522
- parser .add_argument (
2523
- '--force_build' , help = 'Force compilation of a new distribution.' ,
2524
- default = False , type = bool )
2525
- parser .add_argument (
2526
- '--extra_dist_dirs' , help = 'Directories in which to look for distributions' ,
2527
- default = '' )
2528
- parser .add_argument (
2529
- '--require_perfect_match' , help = ('Whether the dist recipes must '
2530
- 'perfectly match those requested.' ),
2531
- type = bool , default = False )
2558
+ '--extra-dist-dirs' , '--extra_dist_dirs' ,
2559
+ dest = 'extra_dist_dirs' , default = '' ,
2560
+ help = 'Directories in which to look for distributions' )
2532
2561
2562
+ add_boolean_option (
2563
+ parser , ["require-perfect-match" , "require_perfect_match" ],
2564
+ default = False ,
2565
+ description = ('Whether the dist recipes must perfectly match '
2566
+ 'those requested' ))
2533
2567
2534
2568
self ._read_configuration ()
2535
2569
@@ -2601,11 +2635,14 @@ def recipes(self, args):
2601
2635
parser = argparse .ArgumentParser (
2602
2636
description = "List all the available recipes" )
2603
2637
parser .add_argument (
2604
- "--compact" , action = "store_true" ,
2638
+ "--compact" , action = "store_true" , default = False ,
2605
2639
help = "Produce a compact list suitable for scripting" )
2606
- parser .add_argument (
2607
- '--color' , type = bool , default = True ,
2608
- help = 'Whether the output should be coloured' )
2640
+
2641
+ add_boolean_option (
2642
+ parser , ["color" ],
2643
+ default = True ,
2644
+ description = 'Whether the output should be colored:' )
2645
+
2609
2646
args = parser .parse_args (args )
2610
2647
2611
2648
if args .compact :
0 commit comments