Skip to content

Commit

Permalink
Add the --show-config option to skool2bin.py
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Aug 15, 2024
1 parent 06b9484 commit 7d578b6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
6 changes: 5 additions & 1 deletion skoolkit/skool2bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from os.path import basename

from skoolkit import SkoolParsingError, get_int_param, info, integer, open_file, parse_int, warn, VERSION
from skoolkit.config import get_config, update_options
from skoolkit.config import get_config, show_config, update_options
from skoolkit.components import get_assembler, get_instruction_utility
from skoolkit.skoolmacro import MacroParsingError, parse_if
from skoolkit.skoolutils import (DIRECTIVES, Memory, parse_address_range, parse_asm_bank_directive,
Expand Down Expand Up @@ -311,6 +311,8 @@ def main(args):
help="Apply @isub, @ssub and @rsub directives (implies --ofix).")
group.add_argument('-R', '--rfix', dest='fix_mode', action='store_const', const=3, default=0,
help="Apply @ofix, @bfix and @rfix directives (implies --rsub).")
group.add_argument('--show-config', dest='show_config', action='store_true',
help="Show configuration parameter values.")
group.add_argument('-s', '--ssub', dest='asm_mode', action='store_const', const=2, default=0,
help="Apply @isub and @ssub directives.")
group.add_argument('-S', '--start', dest='start', metavar='ADDR', type=integer, default=-1,
Expand All @@ -322,6 +324,8 @@ def main(args):
group.add_argument('-w', '--no-warnings', dest='warn', action='store_false',
help="Suppress warnings.")
namespace, unknown_args = parser.parse_known_args(args)
if namespace.show_config:
show_config('skool2bin', config)
skoolfile = namespace.skoolfile
if unknown_args or skoolfile is None:
parser.exit(2, parser.format_help())
Expand Down
5 changes: 3 additions & 2 deletions sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Changelog
-----
* Added support to :ref:`skool2bin.py <skool2bin-conf>` for reading
configuration from `skoolkit.ini`
* Added the ``--ini`` option to :ref:`skool2bin.py` (for setting the value of
a configuration parameter)
* Added the ``--ini`` and ``--show-config`` options to :ref:`skool2bin.py` (for
setting the value of a configuration parameter and for showing all
configuration parameter values)
* Fixed how the 'ADC A,*', 'SBC A,*', 'ADC HL,rr' and 'SBC HL,rr' instructions
affect the half-carry flag
* Fixed how 'BIT n,(IX/Y+d)' affects bits 3 and 5 of the flags in the C version
Expand Down
3 changes: 2 additions & 1 deletion sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ To list the options supported by `skool2bin.py`, run it with no arguments::
--ofix).
-R, --rfix Apply @ofix, @bfix and @rfix directives (implies
--rsub).
--show-config Show configuration parameter values.
-s, --ssub Apply @isub and @ssub directives.
-S ADDR, --start ADDR
Start converting at this address.
Expand Down Expand Up @@ -538,7 +539,7 @@ Configuration parameters may also be set on the command line by using the
| Version | Changes |
+=========+===================================================================+
| 9.4 | Configuration is read from `skoolkit.ini` if present; added the |
| | ``--ini`` option |
| | ``--ini`` and ``--show-config`` options |
+---------+-------------------------------------------------------------------+
| 9.1 | Added the ``--banks`` option |
+---------+-------------------------------------------------------------------+
Expand Down
3 changes: 3 additions & 0 deletions sphinx/source/man/skool2bin.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ OPTIONS
-R, --rfix
Apply @ofix, @bfix and @rfix directives (implies ``--rsub``).

--show-config
Show configuration parameter values.

-s, --ssub
Apply @isub and @ssub directives.

Expand Down
24 changes: 24 additions & 0 deletions tests/test_skool2bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,30 @@ def test_option_R(self):
self.assertEqual(len(error), 0)
self._check_values(skoolfile, exp_binfile, fix_mode=3)

@patch.object(skool2bin, 'get_config', mock_config)
def test_option_show_config(self):
output, error = self.run_skool2bin('--show-config', catch_exit=0)
self.assertEqual(error, '')
exp_output = """
[skool2bin]
Warnings=1
"""
self.assertEqual(dedent(exp_output).strip(), output.rstrip())

def test_option_show_config_read_from_file(self):
ini = """
[skool2bin]
Warnings=0
"""
self.write_text_file(dedent(ini).strip(), 'skoolkit.ini')
output, error = self.run_skool2bin('--show-config', catch_exit=0)
self.assertEqual(error, '')
exp_output = """
[skool2bin]
Warnings=0
"""
self.assertEqual(dedent(exp_output).strip(), output.rstrip())

@patch.object(skool2bin, 'BinWriter', MockBinWriter)
def test_option_s(self):
skoolfile = 'test-s.skool'
Expand Down

0 comments on commit 7d578b6

Please sign in to comment.