@@ -138,6 +138,20 @@ def __init__(self, prog: str) -> None:
138
138
)
139
139
p .add_argument ("--remove" , metavar = "FILE" , nargs = "*" , help = "Files to remove from the run" )
140
140
141
+
142
+ watch_parser = p = subparsers .add_parser ("watch" , help = "Check on a set interval (requires daemon)" )
143
+ p .add_argument ("--log-file" , metavar = "FILE" , type = str , help = "Direct daemon stdout/stderr to FILE" )
144
+ p .add_argument ("files" , metavar = "FILE" , nargs = "+" , help = "File (or directory) to check" )
145
+ p .add_argument (
146
+ "--interval" , metavar = "INTERVAL" , default = 1 , type = int , help = "Time between checks (in seconds)"
147
+ )
148
+ p .add_argument (
149
+ "--export-types" ,
150
+ action = "store_true" ,
151
+ help = "Store types of all expressions in a shared location (useful for inspections)" ,
152
+ )
153
+
154
+
141
155
suggest_parser = p = subparsers .add_parser (
142
156
"suggest" , help = "Suggest a signature or show call sites for a specific function"
143
157
)
@@ -599,7 +613,7 @@ def show_stats(response: Mapping[str, object]) -> None:
599
613
# Special case text output to display just 40 characters of text
600
614
value = repr (value )[1 :- 1 ]
601
615
if len (value ) > 50 :
602
- value = f"{ value [:40 ]} ... { len (value )- 40 } more characters"
616
+ value = f"{ value [:40 ]} ... { len (value ) - 40 } more characters"
603
617
print ("%-24s: %s" % (key , value ))
604
618
continue
605
619
print ("%-24s: %10s" % (key , "%.3f" % value if isinstance (value , float ) else value ))
@@ -611,6 +625,35 @@ def do_hang(args: argparse.Namespace) -> None:
611
625
print (request (args .status_file , "hang" , timeout = 1 ))
612
626
613
627
628
+ @action (watch_parser )
629
+ def do_watch (args : argparse .Namespace ) -> None :
630
+ """Recheck the same set of files every few seconds"""
631
+ response = request (args .status_file , "check" , files = args .files , export_types = args .export_types )
632
+ os .system ("cls" if os .name == "nt" else "clear" )
633
+ previous_output = response ["out" ]
634
+ previous_err = response ["err" ]
635
+ sys .stdout .write (previous_output )
636
+ sys .stdout .flush ()
637
+ sys .stderr .write (previous_err )
638
+ sys .stderr .flush ()
639
+ while True :
640
+ try :
641
+ time .sleep (args .interval )
642
+ response = request (args .status_file , "recheck" , export_types = args .export_types )
643
+ output = response ["out" ]
644
+ err = response ["err" ]
645
+ if output != previous_output or err != previous_err :
646
+ os .system ("cls" if os .name == "nt" else "clear" )
647
+ sys .stdout .write (output )
648
+ sys .stdout .flush ()
649
+ sys .stderr .write (err )
650
+ sys .stderr .flush ()
651
+ previous_output = output
652
+ previous_err = err
653
+ except KeyboardInterrupt :
654
+ break
655
+
656
+
614
657
@action (daemon_parser )
615
658
def do_daemon (args : argparse .Namespace ) -> None :
616
659
"""Serve requests in the foreground."""
0 commit comments