Skip to content

Commit 9100336

Browse files
authored
Show help when no args passed (#1)
* Show help when no args passed * Fix landscape warnings & errors
1 parent f8a4404 commit 9100336

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ clean:
99
rm -rf test/__pycache__
1010
rm -rf zxtools/__pycache__
1111
rm -rf zxtools.egg-info
12+
rm -rf coverage.xml
1213

1314
coverage:
1415
coverage run --source zxtools setup.py test

test/test_hobeta.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def test_args_parser(self):
2424
with self.assertRaises(SystemExit):
2525
hobeta.parse_args(("-h", "-v"))
2626

27+
with self.assertRaises(SystemExit):
28+
hobeta.parse_args(())
29+
2730
temp_in_file = tempfile.mkstemp()[1]
2831
input_file = open(temp_in_file, "w")
2932
input_file.close()

test/test_zeus2txt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def test_args_parser(self):
2525
with self.assertRaises(SystemExit):
2626
zeus2txt.parse_args(("-h", "-v"))
2727

28+
with self.assertRaises(SystemExit):
29+
zeus2txt.parse_args(())
30+
2831
temp_in_file = tempfile.mkstemp()[1]
2932
input_file = open(temp_in_file, "w")
3033
input_file.close()

zxtools/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
# See LICENSE file in the project root for full license information.
99
#
1010

11-
__version__ = '1.0.21'
12-
CHUNK_SIZE = 512 * 1024 # 512 KBytes
11+
__version__ = '1.0.22'
12+
CHUNK_SIZE = 512 * 1024 # 512 KBytes

zxtools/hobeta.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def hobeta_help(*parsed_args):
4141
" F - The first occupied sector or just padding?\n"
4242
" C - File size in TR-DOS sectors\n"
4343
" CHK - Checksum of this header (excluding CHK)")
44+
return parsed_args
4445

4546

4647
def calc_checksum(data):
@@ -153,7 +154,15 @@ def parse_args(args):
153154
help="Show Hobeta header format description")
154155
help_parser.set_defaults(func=hobeta_help)
155156

156-
return parser.parse_args(args)
157+
try:
158+
options = parser.parse_args(args)
159+
if len(args) == 0:
160+
raise ValueError
161+
except ValueError:
162+
parser.print_help()
163+
sys.exit(0)
164+
165+
return options
157166

158167

159168
def main():

zxtools/zeus2txt.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def show_info(*parsed_args):
23-
return
23+
return parsed_args
2424

2525

2626
def read_file(src_file):
@@ -59,6 +59,8 @@ def convert_file(parsed_args):
5959
tab = False
6060
output = parsed_args.output_file
6161
strnum = 0
62+
cur_buffer = ""
63+
cur_line = io.StringIO()
6264
for b in read_file(parsed_args.zeus_file):
6365
if process_string:
6466
cur_buffer += "0x%02X " % b
@@ -87,7 +89,7 @@ def convert_file(parsed_args):
8789
print(ASM_META[b-ASM_FIRST_TOKEN], end="", file=cur_line)
8890
except IndexError:
8991
logger.warning("Token not defined: 0x%02X (%d), at line %05d. "
90-
"Skipped." % (b, b, strnum))
92+
"Skipped.", b, b, strnum)
9193
else:
9294
if not strnum_lo[0]:
9395
strnum_lo = True, b
@@ -135,7 +137,15 @@ def parse_args(args):
135137
action='store_true', help="Include original code in the output file")
136138
convert_parser.set_defaults(func=convert_file)
137139

138-
return parser.parse_args(args)
140+
try:
141+
options = parser.parse_args(args)
142+
if len(args) == 0:
143+
raise ValueError
144+
except ValueError:
145+
parser.print_help()
146+
sys.exit(0)
147+
148+
return options
139149

140150

141151
def main():

0 commit comments

Comments
 (0)