Skip to content

Use herogold.argparse Argument for STORE_BOOL defaults instead of parser.set_defaults #5

Description

@HEROgold

From the review of #2:

parser.setdefaults work, however i'd like to update/use Argument class to handle this behaviour.

Current state

src/funcsort/main.py declares its flags declaratively:

sort_module = Argument("sort-module", action=Actions.STORE_BOOL, default=True, ...)
respect_dependencies = Argument("respect-dependencies", action=Actions.STORE_BOOL, default=True, ...)

but those default=True values are effectively dead, because line 48 overrides them:

parser.set_defaults(check=False, diff=False, recursive=True, sort_module=None, respect_dependencies=None)

The None sentinel is deliberate: it is what lets the config file win unless the user passes the flag explicitly (main.py:85-86). STORE_BOOL registers a --flag/--no-flag pair, and there is currently no way to express "unset" through Argument alone — hence the set_defaults escape hatch.

Desired state

The fix belongs in the herogold.argparse package: Argument / Actions.STORE_BOOL should support a tri-state default natively (True / False / unset), so main.py can drop parser.set_defaults entirely and keep the declarative _Cli block as the single source of truth.

Follow-up

When this is solved, re-review the config/CLI merge lines:

If we can simplify/couple args and settings, this line must be reviewed again.

main.py:85-86:

sort_module = settings.sort_module if args.sort_module is None else args.sort_module
respect_dependencies = settings.respect_dependencies if args.respect_dependencies is None else args.respect_dependencies

Related: #4 (config declaration boilerplate).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions