@@ -235,7 +235,9 @@ def find_endpoint(argv, shortcuts={}):
235
235
indices .append (index )
236
236
return - 1 if len (indices ) == 0 else indices [- 1 ]
237
237
238
- def jgo_parser ():
238
+ _default_log_levels = ('NOTSET' , 'DEBUG' , 'INFO' , 'WARN' , 'ERROR' , 'CRITICAL' , 'FATAL' , 'TRACE' )
239
+
240
+ def jgo_parser (log_levels = _default_log_levels ):
239
241
240
242
epilog = '''
241
243
The endpoint should have one of the following formats:
@@ -254,7 +256,7 @@ def jgo_parser():
254
256
255
257
parser = argparse .ArgumentParser (
256
258
description = 'Run Java main class from maven coordinates.' ,
257
- usage = '%(prog)s [-v] [-u] [-U] [-m] [--ignore-jgorc] [--link-type type] [--additional-jars jar [jar ...]] [--additional-endpoints endpoint [endpoint ...]] [JVM_OPTIONS [JVM_OPTIONS ...]] <endpoint> [main-args]' ,
259
+ usage = '%(prog)s [-v] [-u] [-U] [-m] [-q] [--log-level] [- -ignore-jgorc] [--link-type type] [--additional-jars jar [jar ...]] [--additional-endpoints endpoint [endpoint ...]] [JVM_OPTIONS [JVM_OPTIONS ...]] <endpoint> [main-args]' ,
258
260
epilog = epilog ,
259
261
formatter_class = argparse .RawTextHelpFormatter
260
262
)
@@ -264,19 +266,23 @@ def jgo_parser():
264
266
parser .add_argument ('-m' , '--manage-dependencies' , action = 'store_true' , help = 'use endpoints for dependency management (see "Details" below)' )
265
267
parser .add_argument ('-r' , '--repository' , nargs = '+' , help = 'Add additional maven repository (key=url format)' , default = [], required = False )
266
268
parser .add_argument ('-a' , '--additional-jars' , nargs = '+' , help = 'Add additional jars to classpath' , default = [], required = False )
269
+ parser .add_argument ('-q' , '--quiet' , action = 'store_true' , required = False , help = 'Suppress jgo output, including logging' )
267
270
parser .add_argument ( '--additional-endpoints' , nargs = '+' , help = 'Add additional endpoints' , default = [], required = False )
268
271
parser .add_argument ('--ignore-jgorc' , action = 'store_true' , help = 'Ignore ~/.jgorc' )
269
272
parser .add_argument ('--link-type' , default = None , type = str , help = 'How to link from local maven repository into jgo cache. Defaults to the `links\' setting in ~/.jgorc or \' auto\' if not specified.' , choices = ('hard' , 'soft' , 'copy' , 'auto' ))
273
+ parser .add_argument ('--log-level' , default = None , type = str , help = 'Set log level' , choices = log_levels )
270
274
271
275
return parser
272
276
273
277
def _jgo_main (argv = sys .argv [1 :], stdout = None , stderr = None ):
274
278
275
279
LOG_FORMAT = '%(levelname)s %(asctime)s: %(message)s'
276
- logging .basicConfig (
277
- level = logging .INFO ,
278
- # datefmt = '%Y-%m-%d - %H:%M:%S',
279
- format = LOG_FORMAT )
280
+
281
+ if not ('-q' in argv or '--quiet' in argv ):
282
+ logging .basicConfig (
283
+ level = logging .INFO ,
284
+ # datefmt = '%Y-%m-%d - %H:%M:%S',
285
+ format = LOG_FORMAT )
280
286
281
287
parser = jgo_parser ()
282
288
@@ -390,8 +396,7 @@ def resolve_dependencies(
390
396
manage_dependencies = False ,
391
397
repositories = {},
392
398
shortcuts = {},
393
- verbose = 0
394
- ):
399
+ verbose = 0 ):
395
400
396
401
397
402
endpoint_strings = split_endpoint_string (endpoint_string )
@@ -410,6 +415,10 @@ def resolve_dependencies(
410
415
if not update_cache :
411
416
return primary_endpoint , workspace
412
417
418
+ _logger .info ('First time start-up may be slow. '
419
+ 'Downloaded dependencies will be cached '
420
+ 'for shorter start-up times in subsequent executions.' )
421
+
413
422
if update_cache :
414
423
shutil .rmtree (workspace , True )
415
424
@@ -530,6 +539,7 @@ def run(parser, argv=sys.argv[1:], stdout=None, stderr=None):
530
539
args , unknown = parser .parse_known_args (argv [:endpoint_index ])
531
540
jvm_args = unknown if unknown else []
532
541
program_args = [] if endpoint_index == - 1 else argv [endpoint_index + 1 :]
542
+ if args .log_level : logging .getLogger ().setLevel (logging .getLevelName (args .log_level ))
533
543
534
544
if args .additional_jars is not None and len (args .additional_jars ) > 0 :
535
545
_logger .warning ('The -a, --additional-jars option has been deprecated and will be removed in the future. '
@@ -570,7 +580,6 @@ def run(parser, argv=sys.argv[1:], stdout=None, stderr=None):
570
580
link_type = link_type )
571
581
572
582
main_class_file = os .path .join (workspace , primary_endpoint .main_class , 'mainClass' ) if primary_endpoint .main_class else os .path .join (workspace , 'mainClass' )
573
-
574
583
try :
575
584
with open (main_class_file , 'r' ) as f :
576
585
main_class = f .readline ()
0 commit comments