From e0450de6d9649db52848cf0fabb68787786287eb Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Wed, 9 Oct 2024 15:55:25 +0200 Subject: [PATCH] feat: raw file upload --- CMakeLists.txt | 2 + src/Redmine-CLI/Command/Upload.cpp | 45 +++++++++++++++++ src/Redmine-CLI/Command/Upload.hpp | 80 ++++++++++++++++++++++++++++++ src/Redmine-CLI/Redmine.cpp | 1 + src/Redmine-CLI/Redmine.hpp | 4 ++ 5 files changed, 132 insertions(+) create mode 100644 src/Redmine-CLI/Command/Upload.cpp create mode 100644 src/Redmine-CLI/Command/Upload.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 72b67df..35b19b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,8 @@ add_executable(redmine-cli src/Redmine-CLI/Command/IssueStatus.cpp src/Redmine-CLI/Command/Issue.hpp src/Redmine-CLI/Command/Issue.cpp + src/Redmine-CLI/Command/Upload.hpp + src/Redmine-CLI/Command/Upload.cpp ) target_link_libraries(redmine-cli redmine-api-cpp-static loguru CLI11 tableprinter::tableprinter) target_include_directories(redmine-cli diff --git a/src/Redmine-CLI/Command/Upload.cpp b/src/Redmine-CLI/Command/Upload.cpp new file mode 100644 index 0000000..adcc55e --- /dev/null +++ b/src/Redmine-CLI/Command/Upload.cpp @@ -0,0 +1,45 @@ +/* +* Copyright (C) 2024 Dominik Meyer +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#include +#include +#include "Redmine/API.hpp" +#include +#include + +Command::Upload::Upload(RedmineCLI::Redmine *r) +: +redmine_(r), +output_(TEXT) +{ + + upload_ = redmine_->getCLI().add_subcommand("upload", "raw file upload"); + upload_->add_option("-f,--file", filePath_, "the file to upload")->required(); + upload_->add_option("-n,--name", fileName_, "the filename within redmine")->required(); + upload_->callback([&](){uploadFile_();}); + +} + +void Command::Upload::uploadFile_() const +{ + Redmine::API client{redmine_->getUrl(), redmine_->getToken()}; + + std::string token = client.upload(filePath_, fileName_); + + std::cout << token << std::endl; +} + diff --git a/src/Redmine-CLI/Command/Upload.hpp b/src/Redmine-CLI/Command/Upload.hpp new file mode 100644 index 0000000..2aa894c --- /dev/null +++ b/src/Redmine-CLI/Command/Upload.hpp @@ -0,0 +1,80 @@ +#pragma once +/* +* Copyright (C) 2024 Dominik Meyer +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ +#include +#include +#include +#include +#include +#define LOGURU_WITH_STREAMS 1 +#include +#include + + +// forward declaration +namespace RedmineCLI +{ + class Redmine; +}; + +namespace Command +{ + + /** + * @brief class for processing the CLI11 parsed command lines + * + */ + class Upload + { + + private: + + /// the main redmine cli application context + RedmineCLI::Redmine *redmine_; + + /// enum for identifying supported output types + enum outputType : std::uint16_t + { + /// output is just text + TEXT, + /// output is json + JSON + }; + + /// requested output type + outputType output_; + + std::map outputMap{{"text", TEXT}, {"json", JSON}}; + + /// the file path for uploading files + std::string filePath_; + + /// the filename for uploading files + std::string fileName_; + + CLI::App* upload_; + + void uploadFile_() const; + public: + /** + * @brief Construct a new CLIProcessor object + * + */ + explicit Upload(RedmineCLI::Redmine *r); + + }; // class Upload +}; // namespace Command \ No newline at end of file diff --git a/src/Redmine-CLI/Redmine.cpp b/src/Redmine-CLI/Redmine.cpp index 6c5a5d7..f05f687 100644 --- a/src/Redmine-CLI/Redmine.cpp +++ b/src/Redmine-CLI/Redmine.cpp @@ -41,4 +41,5 @@ version_(nullptr) project_ = std::make_unique(this); issueStatus_ = std::make_unique(this); issue_ = std::make_unique(this); + upload_ = std::make_unique(this); } \ No newline at end of file diff --git a/src/Redmine-CLI/Redmine.hpp b/src/Redmine-CLI/Redmine.hpp index 770dab0..8fb80bc 100644 --- a/src/Redmine-CLI/Redmine.hpp +++ b/src/Redmine-CLI/Redmine.hpp @@ -19,6 +19,7 @@ #include "Redmine-CLI/Command/IssueStatus.hpp" #include "Redmine-CLI/Command/MyAccount.hpp" #include "Redmine-CLI/Command/Project.hpp" +#include "Redmine-CLI/Command/Upload.hpp" #include "Redmine-CLI/Command/Version.hpp" #include #include @@ -68,6 +69,9 @@ namespace RedmineCLI /// pointer to the issue subcommand std::unique_ptr issue_; + /// pointer to the upload subcommand + std::unique_ptr upload_; + public: /**