@@ -419,6 +419,11 @@ def create_parser() -> ArgumentParser:
419
419
)
420
420
)
421
421
422
+ parser .add_argument ("--search" ,
423
+ metavar = '"KEYWORDS"' ,
424
+ type = str ,
425
+ help = "Search for a specific command from a query" )
426
+
422
427
parser .add_argument ('-u' , '--update_cache' ,
423
428
action = 'store_true' ,
424
429
help = "Update the local cache of pages and exit" )
@@ -495,7 +500,6 @@ def main() -> None:
495
500
elif len (sys .argv ) == 1 :
496
501
parser .print_help (sys .stderr )
497
502
sys .exit (1 )
498
-
499
503
if options .list :
500
504
print (get_commands (options .platform ))
501
505
elif options .render :
@@ -504,6 +508,39 @@ def main() -> None:
504
508
with open (command , encoding = 'utf-8' ) as open_file :
505
509
output (open_file .read ().encode ('utf-8' ).splitlines (),
506
510
plain = options .markdown )
511
+ elif options .search :
512
+ command = '-' .join (options .command )
513
+ page = None
514
+ maxprob = 0
515
+ searchquery = options .search .split (' ' )
516
+
517
+ platforms = get_platform_list ()
518
+ for i in get_commands (platforms ):
519
+ if i .startswith (command ):
520
+ for p in platforms :
521
+ result = load_page_from_cache (i , p , options .language )
522
+ if result is not None and have_recent_cache (i , p , options .language ):
523
+ break
524
+ if result is None :
525
+ raise SystemExit ("Please update cache" )
526
+ result = result .decode ("utf-8" )
527
+ result = result .split ()
528
+ for word in searchquery :
529
+ prob = 0
530
+ for line in result :
531
+ if word in line and \
532
+ (line .startswith ('-' ) or line .startswith ('>' )):
533
+ prob += 1
534
+ if prob > maxprob :
535
+ maxprob = prob
536
+ page = i
537
+
538
+ if page :
539
+ result = get_page (page , None , options .platform , options .language )
540
+ output (result , plain = options .markdown )
541
+ else :
542
+ print ("No results found" )
543
+
507
544
else :
508
545
try :
509
546
command = '-' .join (options .command ).lower ()
0 commit comments