@@ -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 = """
@@ -53,15 +54,12 @@ def parse_args() -> ParsedArgs:
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 ("--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 (
63- "--copy-only" , action = "store_true" , help = "Copy to clipboard, suppress stdout (file output with -o still works)"
64- )
62+ parser .add_argument ("-c" , "--copy" , action = "store_true" , help = "Copy to clipboard (suppresses stdout unless -o is used)" )
6563 parser .add_argument (
6664 "-v" ,
6765 "--verbosity" ,
@@ -71,9 +69,19 @@ def parse_args() -> ParsedArgs:
7169 metavar = "[0-3]" ,
7270 help = "Verbosity: 0=ERROR, 1=WARNING, 2=INFO, 3=DEBUG" ,
7371 )
72+ parser .add_argument ("--tokens" , action = "store_true" , help = "Show token count for output" )
73+ parser .add_argument (
74+ "--token-encoding" ,
75+ choices = ["o200k_base" , "o200k_harmony" , "cl100k_base" ],
76+ default = "o200k_base" ,
77+ help = "Tokenizer encoding (default: o200k_base)" ,
78+ )
7479
7580 args = parser .parse_args ()
7681
82+ if args .token_encoding != "o200k_base" and not args .tokens :
83+ print ("Warning: --token-encoding has no effect without --tokens" , file = sys .stderr )
84+
7785 if args .max_depth is not None and args .max_depth < 0 :
7886 print (f"Error: --max-depth must be non-negative, got { args .max_depth } " , file = sys .stderr )
7987 sys .exit (1 )
@@ -97,6 +105,9 @@ def parse_args() -> ParsedArgs:
97105 output_file = None
98106 if args .output_file and args .output_file != "-" :
99107 output_file = Path (args .output_file ).resolve ()
108+ if output_file .is_dir ():
109+ print (f"Error: '{ args .output_file } ' is a directory, not a file." , file = sys .stderr )
110+ sys .exit (1 )
100111
101112 ignore_file = None
102113 if args .ignore_file :
@@ -115,6 +126,7 @@ def parse_args() -> ParsedArgs:
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