Added CLI command to list supported targets in JSON format
This commit is contained in:
@@ -13,10 +13,12 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "src/Services/ProcessService.hpp"
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/Services/PathService.hpp"
|
||||
#include "src/Services/ProcessService.hpp"
|
||||
#include "src/Helpers/BiMap.hpp"
|
||||
|
||||
#include "src/Targets/TargetDescription/TargetDescriptionFile.hpp"
|
||||
|
||||
#include "src/Exceptions/InvalidConfig.hpp"
|
||||
|
||||
@@ -134,6 +136,10 @@ std::map<std::string, std::function<int()>> Application::getCommandHandlersByCom
|
||||
"init",
|
||||
std::bind(&Application::initProject, this)
|
||||
},
|
||||
{
|
||||
"--target-list-machine",
|
||||
std::bind(&Application::presentTargetListMachine, this)
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -387,6 +393,30 @@ int Application::presentVersionMachineText() {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int Application::presentTargetListMachine() {
|
||||
Logger::silence();
|
||||
|
||||
using Targets::TargetFamily;
|
||||
static const auto targetFamilyNames = BiMap<TargetFamily, QString>({
|
||||
{TargetFamily::AVR_8, "AVR8"},
|
||||
{TargetFamily::RISC_V, "RISC-V"},
|
||||
});
|
||||
|
||||
auto output = QJsonArray();
|
||||
|
||||
for (const auto& [configValue, descriptor] : Targets::TargetDescription::TargetDescriptionFile::mapping()) {
|
||||
output.push_back(QJsonObject({
|
||||
{"name" , QString::fromStdString(descriptor.targetName)},
|
||||
{"family" , targetFamilyNames.at(descriptor.targetFamily)},
|
||||
{"configurationValue" , QString::fromStdString(configValue)},
|
||||
}));
|
||||
}
|
||||
|
||||
std::cout << QJsonDocument(output).toJson().toStdString();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int Application::initProject() {
|
||||
auto configFile = QFile(QString::fromStdString(Services::PathService::projectConfigPath()));
|
||||
|
||||
|
||||
@@ -216,6 +216,13 @@ private:
|
||||
*/
|
||||
int presentVersionMachineText();
|
||||
|
||||
/**
|
||||
* Lists all supported targets, in JSON format.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int presentTargetListMachine();
|
||||
|
||||
/**
|
||||
* Initialises a project in the user's working directory.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user