1010import argparse
1111import os
1212import sys
13+ from enum import StrEnum
1314
1415import src .api .config
1516from src .api import errmsg , global_
1617from src .api .config import OPTIONS
18+ from src .api .errmsg import warning_command_line_flag_deprecation
1719from src .zxbasm import asmparse , expr
1820from src .zxbasm .version import VERSION
1921from src .zxbpp import zxbpp
22+ from src .zxbpp .zxbpp import PreprocMode
23+
24+
25+ class FileType (StrEnum ):
26+ BIN = "bin"
27+ SNA = "sna"
28+ TAP = "tap"
29+ TZX = "tzx"
30+ Z80 = "z80"
2031
2132
2233def main (args = None ):
@@ -50,7 +61,8 @@ def main(args=None):
5061 default = None ,
5162 )
5263
53- o_parser .add_argument (
64+ output_file_type_group = o_parser .add_mutually_exclusive_group ()
65+ output_file_type_group .add_argument (
5466 "-T" ,
5567 "--tzx" ,
5668 action = "store_true" ,
@@ -59,7 +71,7 @@ def main(args=None):
5971 help = "Sets output format to tzx (default is .bin)" ,
6072 )
6173
62- o_parser .add_argument (
74+ output_file_type_group .add_argument (
6375 "-t" ,
6476 "--tap" ,
6577 action = "store_true" ,
@@ -68,6 +80,16 @@ def main(args=None):
6880 help = "Sets output format to tzx (default is .bin)" ,
6981 )
7082
83+ output_file_type_group .add_argument (
84+ "-f" ,
85+ "--output-format" ,
86+ type = str ,
87+ choices = [str (x ) for x in FileType ],
88+ required = False ,
89+ help = "Output format" ,
90+ default = OPTIONS .output_file_type ,
91+ )
92+
7193 o_parser .add_argument (
7294 "-B" ,
7395 "--BASIC" ,
@@ -114,7 +136,6 @@ def main(args=None):
114136
115137 if not os .path .exists (options .PROGRAM ):
116138 o_parser .error ("No such file or directory: '%s'" % options .PROGRAM )
117- sys .exit (2 )
118139
119140 OPTIONS .debug_level = int (options .debug )
120141 OPTIONS .input_filename = options .PROGRAM
@@ -127,10 +148,18 @@ def main(args=None):
127148 OPTIONS .force_asm_brackets = options .bracket
128149 OPTIONS .zxnext = options .zxnext
129150
130- if options .tzx :
131- OPTIONS .output_file_type = "tzx"
151+ if options .output_format :
152+ OPTIONS .output_file_type = options .output_format
153+ elif options .tzx :
154+ OPTIONS .output_file_type = FileType .TZX
155+ warning_command_line_flag_deprecation (
156+ f"--tzx (use -f { FileType .TZX } or --output-format={ FileType .TZX } instead)"
157+ )
132158 elif options .tap :
133- OPTIONS .output_file_type = "tap"
159+ OPTIONS .output_file_type = FileType .TAP
160+ warning_command_line_flag_deprecation (
161+ f"--tap (use -f { FileType .TAP } or --output-format={ FileType .TAP } instead)"
162+ )
134163
135164 if not OPTIONS .output_filename :
136165 OPTIONS .output_filename = (
@@ -149,7 +178,7 @@ def main(args=None):
149178 return 4
150179
151180 # Configure the preprocessor to use the asm-preprocessor-lexer
152- zxbpp .setMode ("asm" )
181+ zxbpp .setMode (PreprocMode . ASM )
153182
154183 # Now filter them against the preprocessor
155184 zxbpp .main ([OPTIONS .input_filename ])
0 commit comments