From 7776ba88c3c0593a24d5bd657178849268e70209 Mon Sep 17 00:00:00 2001 From: Nav Date: Fri, 6 May 2022 19:30:43 +0100 Subject: [PATCH] New --version-machine CLI command --- resources/help.txt | 7 ++++--- src/Application.cpp | 15 +++++++++++++++ src/Application.hpp | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/resources/help.txt b/resources/help.txt index 143867b6..d114bc33 100644 --- a/resources/help.txt +++ b/resources/help.txt @@ -7,8 +7,9 @@ If no environment name or command is provided, Bloom will fallback to the enviro If no such environment exists, Bloom will exit. Commands: - --help, -h Displays this help text. - --version, -v Displays the current version number. - init Creates a new Bloom project configuration file (bloom.json), in the working directory. + --help, -h Displays this help text. + --version, -v Displays Bloom's version number. + --version-machine Outputs Bloom's version number in JSON format. + init Creates a new Bloom project configuration file (bloom.json), in the working directory. For more information on getting started with Bloom, please visit https://bloom.oscillate.io/docs/getting-started. diff --git a/src/Application.cpp b/src/Application.cpp index 86cfb254..673920c7 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -287,6 +287,21 @@ namespace Bloom return EXIT_SUCCESS; } + int Application::presentVersionMachineText() { + Logger::silence(); + + std::cout << QJsonDocument(QJsonObject({ + {"version", QString::fromStdString(Application::VERSION.toString())}, + {"components", QJsonObject({ + {"major", Application::VERSION.getMajor()}, + {"minor", Application::VERSION.getMinor()}, + {"patch", Application::VERSION.getPatch()}, + })}, + })).toJson().toStdString(); + + return EXIT_SUCCESS; + } + int Application::initProject() { auto configFile = QFile( QString::fromStdString(std::filesystem::current_path().string() + "/bloom.json") diff --git a/src/Application.hpp b/src/Application.hpp index 3dc20a69..846c25ef 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -156,6 +156,10 @@ namespace Bloom "-v", std::bind(&Application::presentVersionText, this) }, + { + "--version-machine", + std::bind(&Application::presentVersionMachineText, this) + }, { "init", std::bind(&Application::initProject, this) @@ -210,6 +214,13 @@ namespace Bloom */ int presentVersionText(); + /** + * Presents the current Bloom version number, in JSON format. + * + * @return + */ + int presentVersionMachineText(); + /** * Initialises a project in the user's working directory. *