[commands] Enhance Command Sendable implementations (#4822)

This commit is contained in:
Starlight220
2022-12-16 04:28:52 +02:00
committed by GitHub
parent 7713f68772
commit fbabd0ef15
33 changed files with 239 additions and 17 deletions

View File

@@ -10,11 +10,14 @@
#endif
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include <wpi/sendable/SendableBuilder.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/PrintCommand.h"
@@ -122,6 +125,21 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
return m_interruptBehavior;
}
void InitSendable(wpi::SendableBuilder& builder) override {
CommandBase::InitSendable(builder);
builder.AddStringProperty(
"selected",
[this] {
if (m_selectedCommand) {
return m_selectedCommand->GetName();
} else {
return std::string{"null"};
}
},
nullptr);
}
protected:
std::unique_ptr<Command> TransferOwnership() && override {
return std::make_unique<SelectCommand>(std::move(*this));