Skip to content

Commit

Permalink
Refactor settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Feb 5, 2024
1 parent 83e6f81 commit 3362840
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion autocomplete.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _shtab_musescore_manager_options=(
"--compress[Save an uncompressed MuseScore file (\*.mscx) as a compressed file (\*.mscz).]"
"(- : *)"{-V,--version}"[show program\'s version number and exit]"
"*"{-v,--verbose}"[Make commands more verbose. You can specifiy multiple arguments (. g.\: -vvv) to make the command more verbose.]"
{-k,--color,--no-color}"[Colorize the command line print statements. (default\: True)]:general_color:"
{-k,--color,--no-color}"[Colorize the command line print statements. (default\: True)]:info_color:"
"--diff[Show a diff of the XML file before and after the manipulation.]"
"--print-xml[Print the XML markup of the score.]"
{-c,--clean-meta}"[Clean the meta data fields. Possible values\: \„all\“ or a comma separated list of fields, for example\: \„field_one,field_two\“.]:meta_clean:"
Expand Down
12 changes: 6 additions & 6 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def setup_parser() -> argparse.ArgumentParser:
"-v",
"--verbose",
action="count",
dest="general_verbose",
dest="info_verbose",
default=0,
help="Make commands more verbose. You can specifiy "
"multiple arguments (. g.: -vvv) to make the command more "
Expand All @@ -176,22 +176,22 @@ def setup_parser() -> argparse.ArgumentParser:
"-k",
"--color",
action=argparse.BooleanOptionalAction,
dest="general_color",
dest="info_color",
default=True,
help="Colorize the command line print statements.",
)

info_group.add_argument(
"--diff",
action="store_true",
dest="general_diff",
dest="info_diff",
help="Show a diff of the XML file before and after the manipulation.",
)

info_group.add_argument(
"--print-xml",
action="store_true",
dest="general_print_xml",
dest="info_print_xml",
help="Print the XML markup of the score.",
)

Expand Down Expand Up @@ -976,10 +976,10 @@ def list_styles(version: int) -> None:
if args.export_extension:
score.export.to_extension(args.export_extension)

if args.general_diff:
if args.info_diff:
score.print_diff()

if args.general_print_xml:
if args.info_print_xml:
print(score.xml_string)

if not args.general_dry_run:
Expand Down
4 changes: 2 additions & 2 deletions mscxyz/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def set(self, name: str, value: Any) -> None:
setattr(obj, last, value)

def diff(self, args: DefaultArguments) -> None:
if args.general_verbose == 0:
if args.info_verbose == 0:
return
pre = self.pre

Expand All @@ -341,7 +341,7 @@ def diff(self, args: DefaultArguments) -> None:
for name in self.names:
if name in pre and pre[name] or name in post and post[name]:
field = self.get_field(name)
if field.verbosity > args.general_verbose:
if field.verbosity > args.info_verbose:
continue

pre_value = None
Expand Down
12 changes: 7 additions & 5 deletions mscxyz/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ class DefaultArguments:
general_catch_errors: bool = False
general_mscore: bool = False
general_executable: Optional[str] = None
general_verbose: int = 0
general_color: bool = True
general_diff: bool = False
general_print_xml: bool = False

# Groups alphabetically
# in groups related not alphabetically
Expand All @@ -36,6 +32,12 @@ class DefaultArguments:
export_extension: Optional[str] = None
export_compress: bool = False

# info
info_verbose: int = 0
info_color: bool = True
info_diff: bool = False
info_print_xml: bool = False

# help
help_markdown: bool = False
help_rst: bool = False
Expand Down Expand Up @@ -165,7 +167,7 @@ def merge_config_into_args(

for arg in [
"general_backup",
"general_colorize",
"info_colorize",
"general_dry_run",
"general_mscore",
"help_markdown",
Expand Down
2 changes: 1 addition & 1 deletion mscxyz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def colorize(
color('“{}”'.format(post[field]), 'yellow')
"""
settings = get_args()
if settings.general_color:
if settings.info_color:
return termcolor.colored(text, color, on_color)
else:
return text
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class TestArgparse:
def test_args_general(self) -> None:
args = get_args(["."])
assert args.general_backup is False
assert args.general_color is True
assert args.info_color is True
assert args.general_dry_run is False
assert args.selection_glob == "*.msc[xz]"
assert args.general_mscore is False
assert args.general_verbose == 0
assert args.info_verbose == 0
assert args.path == ["."]

def test_args_clean(self) -> None:
Expand Down Expand Up @@ -51,15 +51,15 @@ def test_args_general_rename(self) -> None:
class TestVerbosity:
def test_0(self) -> None:
args = get_args([])
assert args.general_verbose == 0
assert args.info_verbose == 0

def test_1(self) -> None:
args = get_args(["-v"])
assert args.general_verbose == 1
assert args.info_verbose == 1

def test_2(self) -> None:
args = get_args(["-vv"])
assert args.general_verbose == 2
assert args.info_verbose == 2


class TestCommandlineInterface:
Expand Down

0 comments on commit 3362840

Please sign in to comment.