Skip to content

feat: add command-level constraint framework @W-20534184@#1580

Merged
soridalac merged 10 commits intomainfrom
d/W-20534184
Apr 30, 2026
Merged

feat: add command-level constraint framework @W-20534184@#1580
soridalac merged 10 commits intomainfrom
d/W-20534184

Conversation

@jfeingold35
Copy link
Copy Markdown
Contributor

This PR is the implementation of a syntax for command-level constraints. It will close #1507 when it is finally merged.

@W-20534184@

@git2gus
Copy link
Copy Markdown

git2gus Bot commented Apr 17, 2026

Git2Gus App is installed but the .git2gus/config.json doesn't have right values. You should add the required configuration.

@jfeingold35 jfeingold35 force-pushed the d/W-20534184 branch 4 times, most recently from 11fa9fd to 3f7bad4 Compare April 22, 2026 23:19
@jfeingold35 jfeingold35 marked this pull request as ready for review April 23, 2026 14:35
Comment thread src/constraints.ts
// istanbul ignore if - should be unreachable
if (this.condition) {
throw new Error('FILLER: DUPLICATE CONDITION')
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do this need to throw a message instead?
example: throw new Error(Misconfigured constraint: duplicate condition set on ${this.getName()})

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.

In theory this should be unreachable, but yeah, can't hurt to have a specific message here.

Comment thread src/command.ts Outdated
const opts = {
context: this,
...options,
constraints: options.constraints,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add constraints here is redundant of ...options or is this intentional to override?

in ...options:

export type Input<TFlags extends FlagOutput, BFlags extends FlagOutput, AFlags extends ArgOutput> = {
  flags?: FlagInput<TFlags>
  baseFlags?: FlagInput<BFlags>
  constraints?: Constraint[] | undefined
  enableJsonFlag?: true | false
  args?: ArgInput<AFlags>
  strict?: boolean | undefined
  context?: ParserContext
  '--'?: boolean
}

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.

Oh, good catch. I'll remove the constraints declaration here. It serves no purpose.

Comment thread src/constraints.ts Outdated
* Declare a set of flags to be evaluated as one instead of separately.
*
* @example
* flag('foo').is.dependentOn(combinationOf('bar', 'baz))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mini typo 'baz'

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.

Oh good catch!

@soridalac
Copy link
Copy Markdown
Contributor

QA notes:
Create a demo-constraints.ts flag constraints for parser, ran a demo script covering all constraint types.
Using: yarn ts-node demo-constraints.ts

✅ : mutuallyExclusive — --json and --csv cannot both be used at the same time.
✅ : mutuallyDependent — --user and --password must be used together or not at all.
✅ : dependentOn — --output requires --format to also be present.
✅ : exclusiveWith — --verbose cannot be used alongside --quiet.
✅ : requiredAny — at least one of --file, --stdin, or --url must be provided.
✅ : requiredAll — both --host and --port must always be present.
✅ : requiredAtLeastN — at least 2 of --a, --b, --c must be provided.
✅ : conditional (when.thisIsTrue) — --target is only required when --mode equals deploy.

@soridalac soridalac merged commit 2f7e34a into main Apr 30, 2026
87 checks passed
@soridalac soridalac deleted the d/W-20534184 branch April 30, 2026 18:29
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.

New flag Constraints API Proposal

2 participants