Skip to content

Global --project flag (before subcommand) is silently ignored; only subcommand-level honored #3

Description

@jumbodaddystack

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.

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