Summary
The top-level/global --project PATH flag is silently ignored. Only the subcommand-level --project is honored. When the global flag is used from a directory that is not itself a project, the command fails as if no project was specified.
Reproduction
crumb init --project /tmp/store # create a store somewhere
cd /some/other/dir # cwd is NOT a project
crumb --project /tmp/store search foo # ❌ exit 2: "no .project-memory/ found at /some/other/dir"
crumb search --project /tmp/store foo # ✅ works
Observed on crumb-kit==0.1.0 (module breadcrumbs, record schema_version 1).
It "appears" to work only when cwd already happens to be the target project, because then the ignored flag is redundant.
Expected
--project should resolve identically regardless of whether it is placed before or after the subcommand. --help advertises --project at both the top level and on each subcommand, implying both should work.
Likely root cause
Classic argparse subparser-default trap: each subparser redefines --project with default=os.getcwd() (or equivalent), so when the subcommand parses, its default overwrites the value the top-level parser already placed in the namespace.
Suggested fixes (any one)
- Set the subparser's
--project default to argparse.SUPPRESS and fall back to the global value.
- Define
--project once on a shared parent parser via parents=[common] and don't re-add it per subcommand.
- After parsing, resolve via
getattr(args, "project", None) or global_project.
Notes
- Exit code is a correct
2 on failure, so CI/scripting integrity is otherwise fine — this is purely flag-position inconsistency.
Summary
The top-level/global
--project PATHflag is silently ignored. Only the subcommand-level--projectis honored. When the global flag is used from a directory that is not itself a project, the command fails as if no project was specified.Reproduction
Observed on
crumb-kit==0.1.0(modulebreadcrumbs, record schema_version 1).It "appears" to work only when
cwdalready happens to be the target project, because then the ignored flag is redundant.Expected
--projectshould resolve identically regardless of whether it is placed before or after the subcommand.--helpadvertises--projectat both the top level and on each subcommand, implying both should work.Likely root cause
Classic argparse subparser-default trap: each subparser redefines
--projectwithdefault=os.getcwd()(or equivalent), so when the subcommand parses, its default overwrites the value the top-level parser already placed in the namespace.Suggested fixes (any one)
--projectdefault toargparse.SUPPRESSand fall back to the global value.--projectonce on a shared parent parser viaparents=[common]and don't re-add it per subcommand.getattr(args, "project", None) or global_project.Notes
2on failure, so CI/scripting integrity is otherwise fine — this is purely flag-position inconsistency.