Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Add withRequirements decorator #7791

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheComputer314
Copy link
Contributor

Small decorator to slightly simplify command compositions that modify subsystem requirements.

TODO:

  • C++
  • Unit tests

Copy link
Contributor

This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR.

@github-actions github-actions bot added the component: command-based WPILib Command Based Library label Feb 15, 2025
@KangarooKoala
Copy link
Contributor

Small decorator to slightly simplify command compositions that modify subsystem requirements.

I don't entirely follow- Could you provide an example of when this might be used? /cur

@TheComputer314
Copy link
Contributor Author

public class Superstructure extends SubsystemBase {
  private Command expose(Command internal) {
    var proxied = internal.asProxy();
    proxied.addRequirements(this);
    return proxied;
  }
}

The above can be simplified to:

public class Superstructure extends SubsystemBase {
  private Command expose(Command internal) {
    return internal.withRequirements(this);
  }
}

Oblarg posted a similar class in the Discord as a way to manage nested Subsystems, but it used a .withRequirements() decorator that didn't exist yet.

I know it's a niche decorator with niche use cases, but it's pretty simple to add.

@KangarooKoala
Copy link
Contributor

Makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: command-based WPILib Command Based Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants