Skip to content

FR: Support command-scoped environment defaults for common CLI options #473

Description

@YewFence

Motivation

Currently, configuring persistent default behaviors for sem across different execution environments (such as CI pipelines, editor integration, or AI agent workflows) requires either passing long flags on every invocation or maintaining custom shell wrappers around specific subcommands.

For example, in agent-driven code reviews, running sem diff --verbose --format markdown provides an ideal balance—it keeps the entity-level classification alongside concrete inline diffs, which is significantly more useful for an agent than a summary-only output or a huge JSON payload. However, repeating these options across frequent invocations is inconvenient.

Possible Approach

To avoid cross-command collisions (since options like --format might accept different values depending on the subcommand), one intuitive design could be command-scoped environment variables.

For instance, mapping to sem diff:

Environment variable Equivalent CLI option Example value
SEM_DIFF_FORMAT --format md
SEM_DIFF_VERBOSE --verbose 1
SEM_DIFF_COLOR --color never
SEM_DIFF_NO_COSMETICS --no-cosmetics 1
SEM_DIFF_FILE_EXTS --file-exts .py,.rs

Note: The pattern above (SEM_<COMMAND>_<OPTION>) is just one suggestion to handle scoping cleanly. I’d love to hear any other thoughts.

The other commands can be handled in the similar way.

Open Question: Handling Boolean Flags

For boolean switches like --verbose (which currently act as binary presence flags rather than key-value pairs), overriding a set environment variable through flag is logically impossible when an environment variable is set (e.g., SEM_DIFF_VERBOSE=1).

A few non-breaking approaches that come to mind, one of this is allowing explicit value assignments**: Accept --verbose=false or --verbose=0 to override an enabled environment default, while keeping bare --verbose acting as true, or just adding description in docs to suggest user to use inline env overrides SEM_DIFF_VERBOSE=0 sem diff.

English is not my first language — sorry if any phrasing sounds unnatural.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions