@@ -19,7 +19,8 @@ class ParsedArgs:
1919 no_content : bool
2020 max_file_bytes : Optional [int ]
2121 copy : bool
22- copy_only : bool
22+ show_tokens : bool
23+ token_encoding : str
2324
2425
2526DEFAULT_IGNORES_HELP = """
@@ -49,31 +50,35 @@ def parse_args() -> ParsedArgs:
4950 formatter_class = argparse .RawDescriptionHelpFormatter ,
5051 )
5152
52- parser .add_argument ("--version" , action = "version" , version = f"%(prog)s { __version__ } " )
53+ parser .add_argument ("-v" , "- -version" , action = "version" , version = f"%(prog)s { __version__ } " )
5354 parser .add_argument ("directory" , nargs = "?" , default = "." , help = "The directory to analyze" )
5455 parser .add_argument ("-i" , "--ignore-file" , default = None , help = "Path to custom ignore file" )
5556 parser .add_argument ("-o" , "--output-file" , default = None , help = "Output file (default: stdout, use '-' to force stdout)" )
56- parser .add_argument ("-- format" , choices = ["yaml" , "json" , "text" ], default = "yaml" , help = "Output format" )
57+ parser .add_argument ("-f" , "-- format" , choices = ["yaml" , "json" , "text" , "md " ], default = "yaml" , help = "Output format" )
5758 parser .add_argument ("--no-default-ignores" , action = "store_true" , help = "Disable all default ignores" )
5859 parser .add_argument ("--max-depth" , type = int , default = None , metavar = "N" , help = "Maximum traversal depth" )
5960 parser .add_argument ("--no-content" , action = "store_true" , help = "Skip file contents (structure only)" )
6061 parser .add_argument ("--max-file-bytes" , type = int , default = None , metavar = "N" , help = "Skip files larger than N bytes" )
61- parser .add_argument ("-c" , "--copy" , action = "store_true" , help = "Copy output to clipboard" )
62+ parser .add_argument ("-c" , "--copy" , action = "store_true" , help = "Copy to clipboard (suppresses stdout unless -o is used) " )
6263 parser .add_argument (
63- "--copy-only" , action = "store_true" , help = "Copy to clipboard, suppress stdout (file output with -o still works)"
64+ "--log-level" ,
65+ choices = ["error" , "warning" , "info" , "debug" ],
66+ default = "error" ,
67+ help = "Log level (default: error)" ,
6468 )
69+ parser .add_argument ("-t" , "--tokens" , action = "store_true" , help = "Show token count for output" )
6570 parser .add_argument (
66- "-v" ,
67- "--verbosity" ,
68- type = int ,
69- choices = range (0 , 4 ),
70- default = 0 ,
71- metavar = "[0-3]" ,
72- help = "Verbosity: 0=ERROR, 1=WARNING, 2=INFO, 3=DEBUG" ,
71+ "--token-encoding" ,
72+ choices = ["o200k_base" , "o200k_harmony" , "cl100k_base" ],
73+ default = "o200k_base" ,
74+ help = "Tokenizer encoding (default: o200k_base)" ,
7375 )
7476
7577 args = parser .parse_args ()
7678
79+ if args .token_encoding != "o200k_base" and not args .tokens :
80+ print ("Warning: --token-encoding has no effect without --tokens" , file = sys .stderr )
81+
7782 if args .max_depth is not None and args .max_depth < 0 :
7883 print (f"Error: --max-depth must be non-negative, got { args .max_depth } " , file = sys .stderr )
7984 sys .exit (1 )
@@ -97,6 +102,9 @@ def parse_args() -> ParsedArgs:
97102 output_file = None
98103 if args .output_file and args .output_file != "-" :
99104 output_file = Path (args .output_file ).resolve ()
105+ if output_file .is_dir ():
106+ print (f"Error: '{ args .output_file } ' is a directory, not a file." , file = sys .stderr )
107+ sys .exit (1 )
100108
101109 ignore_file = None
102110 if args .ignore_file :
@@ -105,16 +113,20 @@ def parse_args() -> ParsedArgs:
105113 print (f"Error: Ignore file '{ args .ignore_file } ' does not exist." , file = sys .stderr )
106114 sys .exit (1 )
107115
116+ log_level_map = {"error" : 0 , "warning" : 1 , "info" : 2 , "debug" : 3 }
117+ verbosity = log_level_map [args .log_level ]
118+
108119 return ParsedArgs (
109120 root_dir = root_dir ,
110121 ignore_file = ignore_file ,
111122 output_file = output_file ,
112123 no_default_ignores = args .no_default_ignores ,
113- verbosity = args . verbosity ,
124+ verbosity = verbosity ,
114125 output_format = args .format ,
115126 max_depth = args .max_depth ,
116127 no_content = args .no_content ,
117128 max_file_bytes = args .max_file_bytes ,
118- copy = args .copy or args .copy_only ,
119- copy_only = args .copy_only ,
129+ copy = args .copy ,
130+ show_tokens = args .tokens ,
131+ token_encoding = args .token_encoding ,
120132 )
0 commit comments