[commands] Deprecate proxy supplier constructor (#6553)

This commit is contained in:
DeltaDizzy
2024-04-29 23:11:29 -05:00
committed by GitHub
parent c71db8ea9c
commit a9cfd0d0f9
6 changed files with 51 additions and 7 deletions

View File

@@ -4,6 +4,8 @@
#include "frc2/command/Commands.h"
#include <wpi/deprecated.h>
#include "frc2/command/ConditionalCommand.h"
#include "frc2/command/DeferredCommand.h"
#include "frc2/command/FunctionalCommand.h"
@@ -60,6 +62,7 @@ CommandPtr cmd::Print(std::string_view msg) {
return PrintCommand(msg).ToPtr();
}
WPI_IGNORE_DEPRECATED
CommandPtr cmd::DeferredProxy(wpi::unique_function<Command*()> supplier) {
return ProxyCommand(std::move(supplier)).ToPtr();
}
@@ -67,6 +70,7 @@ CommandPtr cmd::DeferredProxy(wpi::unique_function<Command*()> supplier) {
CommandPtr cmd::DeferredProxy(wpi::unique_function<CommandPtr()> supplier) {
return ProxyCommand(std::move(supplier)).ToPtr();
}
WPI_UNIGNORE_DEPRECATED
CommandPtr cmd::Wait(units::second_t duration) {
return WaitCommand(duration).ToPtr();

View File

@@ -5,10 +5,12 @@
#include "frc2/command/ProxyCommand.h"
#include <fmt/core.h>
#include <wpi/deprecated.h>
#include <wpi/sendable/SendableBuilder.h>
using namespace frc2;
WPI_IGNORE_DEPRECATED
ProxyCommand::ProxyCommand(wpi::unique_function<Command*()> supplier)
: m_supplier(std::move(supplier)) {}
@@ -18,9 +20,10 @@ ProxyCommand::ProxyCommand(wpi::unique_function<CommandPtr()> supplier)
holder = supplier();
return holder->get();
}) {}
WPI_UNIGNORE_DEPRECATED
ProxyCommand::ProxyCommand(Command* command)
: ProxyCommand([command] { return command; }) {
: m_supplier([command] { return command; }) {
SetName(fmt::format("Proxy({})", command->GetName()));
}

View File

@@ -12,6 +12,8 @@
#include <utility>
#include <vector>
#include <wpi/deprecated.h>
#include "frc2/command/CommandPtr.h"
#include "frc2/command/Requirements.h"
#include "frc2/command/SelectCommand.h"
@@ -155,11 +157,15 @@ CommandPtr Defer(wpi::unique_function<CommandPtr()> supplier,
/**
* Constructs a command that schedules the command returned from the supplier
* when initialized, and ends when it is no longer scheduled. The supplier is
* called when the command is initialized.
* called when the command is initialized. As a replacement, consider using
* `Defer(supplier).AsProxy()`.
*
* @param supplier the command supplier
*/
[[nodiscard]]
WPI_IGNORE_DEPRECATED
[[nodiscard]] [[deprecated(
"The ProxyCommand supplier constructor has been deprecated. Use "
"Defer(supplier).AsProxy() instead.")]]
CommandPtr DeferredProxy(wpi::unique_function<Command*()> supplier);
/**
@@ -169,9 +175,11 @@ CommandPtr DeferredProxy(wpi::unique_function<Command*()> supplier);
*
* @param supplier the command supplier
*/
[[nodiscard]]
[[nodiscard]] [[deprecated(
"The ProxyCommand supplier constructor has been deprecated. Use "
"Defer(supplier).AsProxy() instead.")]]
CommandPtr DeferredProxy(wpi::unique_function<CommandPtr()> supplier);
WPI_UNIGNORE_DEPRECATED
// Command Groups
namespace impl {

View File

@@ -7,6 +7,7 @@
#include <memory>
#include <wpi/FunctionExtras.h>
#include <wpi/deprecated.h>
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
@@ -36,8 +37,16 @@ class ProxyCommand : public CommandHelper<Command, ProxyCommand> {
* DeferredCommand} instead.
*
* @param supplier the command supplier
* @deprecated This constructor's similarity to {@link DeferredCommand} is
* confusing and opens potential footguns for users who do not fully
* understand the semantics and implications of proxying, but who simply want
* runtime construction. Users who do know what they are doing and need a
* supplier-constructed proxied command should instead proxy a DeferredCommand
* using the <code>AsProxy</code> decorator.
* @see DeferredCommand
*/
WPI_IGNORE_DEPRECATED
[[deprecated("Proxy a DeferredCommand instead")]]
explicit ProxyCommand(wpi::unique_function<Command*()> supplier);
/**
@@ -49,9 +58,17 @@ class ProxyCommand : public CommandHelper<Command, ProxyCommand> {
* DeferredCommand} instead.
*
* @param supplier the command supplier
* @deprecated This constructor's similarity to {@link DeferredCommand} is
* confusing and opens potential footguns for users who do not fully
* understand the semantics and implications of proxying, but who simply want
* runtime construction. Users who do know what they are doing and need a
* supplier-constructed proxied command should instead proxy a DeferredCommand
* using the <code>AsProxy</code> decorator.
* @see DeferredCommand
*/
[[deprecated("Proxy a DeferredCommand instead")]]
explicit ProxyCommand(wpi::unique_function<CommandPtr()> supplier);
WPI_UNIGNORE_DEPRECATED
/**
* Creates a new ProxyCommand that schedules the given command when