Skip to content

Commit

Permalink
Show help when no args passed (#1)
Browse files Browse the repository at this point in the history
* Show help when no args passed
* Fix landscape warnings & errors
  • Loading branch information
jia3ep committed Jun 17, 2016
1 parent f8a4404 commit 9100336
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -9,6 +9,7 @@ clean:
rm -rf test/__pycache__
rm -rf zxtools/__pycache__
rm -rf zxtools.egg-info
rm -rf coverage.xml

coverage:
coverage run --source zxtools setup.py test
Expand Down
3 changes: 3 additions & 0 deletions test/test_hobeta.py
Expand Up @@ -24,6 +24,9 @@ def test_args_parser(self):
with self.assertRaises(SystemExit):
hobeta.parse_args(("-h", "-v"))

with self.assertRaises(SystemExit):
hobeta.parse_args(())

temp_in_file = tempfile.mkstemp()[1]
input_file = open(temp_in_file, "w")
input_file.close()
Expand Down
3 changes: 3 additions & 0 deletions test/test_zeus2txt.py
Expand Up @@ -25,6 +25,9 @@ def test_args_parser(self):
with self.assertRaises(SystemExit):
zeus2txt.parse_args(("-h", "-v"))

with self.assertRaises(SystemExit):
zeus2txt.parse_args(())

temp_in_file = tempfile.mkstemp()[1]
input_file = open(temp_in_file, "w")
input_file.close()
Expand Down
4 changes: 2 additions & 2 deletions zxtools/__init__.py
Expand Up @@ -8,5 +8,5 @@
# See LICENSE file in the project root for full license information.
#

__version__ = '1.0.21'
CHUNK_SIZE = 512 * 1024 # 512 KBytes
__version__ = '1.0.22'
CHUNK_SIZE = 512 * 1024 # 512 KBytes
11 changes: 10 additions & 1 deletion zxtools/hobeta.py
Expand Up @@ -41,6 +41,7 @@ def hobeta_help(*parsed_args):
" F - The first occupied sector or just padding?\n"
" C - File size in TR-DOS sectors\n"
" CHK - Checksum of this header (excluding CHK)")
return parsed_args


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

return parser.parse_args(args)
try:
options = parser.parse_args(args)
if len(args) == 0:
raise ValueError
except ValueError:
parser.print_help()
sys.exit(0)

return options


def main():
Expand Down
16 changes: 13 additions & 3 deletions zxtools/zeus2txt.py
Expand Up @@ -20,7 +20,7 @@


def show_info(*parsed_args):
return
return parsed_args


def read_file(src_file):
Expand Down Expand Up @@ -59,6 +59,8 @@ def convert_file(parsed_args):
tab = False
output = parsed_args.output_file
strnum = 0
cur_buffer = ""
cur_line = io.StringIO()
for b in read_file(parsed_args.zeus_file):
if process_string:
cur_buffer += "0x%02X " % b
Expand Down Expand Up @@ -87,7 +89,7 @@ def convert_file(parsed_args):
print(ASM_META[b-ASM_FIRST_TOKEN], end="", file=cur_line)
except IndexError:
logger.warning("Token not defined: 0x%02X (%d), at line %05d. "
"Skipped." % (b, b, strnum))
"Skipped.", b, b, strnum)
else:
if not strnum_lo[0]:
strnum_lo = True, b
Expand Down Expand Up @@ -135,7 +137,15 @@ def parse_args(args):
action='store_true', help="Include original code in the output file")
convert_parser.set_defaults(func=convert_file)

return parser.parse_args(args)
try:
options = parser.parse_args(args)
if len(args) == 0:
raise ValueError
except ValueError:
parser.print_help()
sys.exit(0)

return options


def main():
Expand Down

0 comments on commit 9100336

Please sign in to comment.