Skip to content

fix(extract): reject invalid CLI arguments#2026

Open
oleksii-tumanov wants to merge 1 commit into
Graphify-Labs:v8from
oleksii-tumanov:fix/extract-cli-argument-validation
Open

fix(extract): reject invalid CLI arguments#2026
oleksii-tumanov wants to merge 1 commit into
Graphify-Labs:v8from
oleksii-tumanov:fix/extract-cli-argument-validation

Conversation

@oleksii-tumanov

@oleksii-tumanov oleksii-tumanov commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • parse and validate graphify extract arguments from one declarative option schema
  • reject unknown options, missing values, unsupported empty/assignment forms, and extra positional arguments with exit code 2 before path or output work
  • enforce the documented 0–100 --exclude-hubs range during parsing instead of returning a conversion traceback
  • preserve supported spaced/inline forms, repeated-option semantics, and intentional empty PostgreSQL DSNs while omitting unknown option values from error output

Result

$ graphify extract . --unknown=value
error: unknown extract option: --unknown

Tests

  • python -m pytest tests/ -q --tb=short — 3511 passed, 33 skipped
  • python -m pytest tests/test_extract_cli_args.py tests/test_extract_cli.py -q --tb=short — 116 passed
  • python -m ruff check graphify/cli.py tests/test_extract_cli_args.py
  • all five tools.skillgen checks
  • graphify update .

Closes #2025.

Related to #2004.

@oleksii-tumanov
oleksii-tumanov force-pushed the fix/extract-cli-argument-validation branch from 5f293e1 to ec6a901 Compare July 19, 2026 07:40
Comment thread graphify/cli.py
print(f"error: path not found: {target}", file=sys.stderr)
sys.exit(1)

backend: str | None = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument parsing logic is easy to follow. Would using argparse simplify maintenance as the number of CLI options continues to grow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. argparse could make sense as a broader CLI refactor. This PR is intentionally focused on validating the existing extract arguments.

Comment thread graphify/cli.py
"cli_cargo": False,
"cli_allow_partial": False,
"no_cluster": False,
"dedup_llm": False,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice validation for the target path. Should we also validate that out_dir is writable before proceeding to avoid failing later in the execution?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I would handle this in a follow-up by catching the actual OSError, since a pre-check can become stale.

Comment thread graphify/cli.py
code_only: bool = parsed["code_only"]
no_gitignore: bool = parsed["no_gitignore"]
global_repo_tag: str | None = parsed["global_repo_tag"]
cli_max_workers: int | None = parsed["cli_max_workers"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the dedicated _parse_int() helper. Would it make sense to follow the same pattern for float(args[i + 1]) (e.g. --exclude-hubs) to keep error handling consistent across numeric arguments?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This PR already routes --exclude-hubs through _parse_percentile() for both spaced and = forms, with consistent conversion and range errors.

@oleksii-tumanov
oleksii-tumanov force-pushed the fix/extract-cli-argument-validation branch from ec6a901 to dd9ec20 Compare July 21, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract: validate unknown, missing and extra CLI arguments

2 participants