File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change 22import logging
33import sys
44from argparse import BooleanOptionalAction , FileType
5+ from pathlib import Path
56from typing import NoReturn
67
78from rich .console import Console as RichConsole
@@ -62,7 +63,7 @@ def run(cls, args: list[str] | None = None) -> None:
6263 parser .add_argument (
6364 "--output-file" ,
6465 "-o" ,
65- type = FileType ( "w" ) ,
66+ type = Path ,
6667 help = "output file path. default is [lit]stdout[/]." ,
6768 )
6869
@@ -93,14 +94,19 @@ def run(cls, args: list[str] | None = None) -> None:
9394 try :
9495 from cmdcomp import completion , config
9596
96- print (
97- completion .generate (
98- space .shell_type ,
99- config .load (space .file ),
100- ),
101- file = space .output_file ,
97+ output_file : Path | None = space .output_file
98+
99+ output = completion .generate (
100+ space .shell_type ,
101+ config .load (space .file ),
102102 )
103103
104+ if output_file :
105+ with open (output_file , "w" ) as f :
106+ f .write (output )
107+ else :
108+ print (output )
109+
104110 except Exception as e :
105111 if space .verbose :
106112 logger .exception (e )
You can’t perform that action at this time.
0 commit comments