feat: raw file upload
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Dominik Meyer 2024-10-09 15:55:25 +02:00
parent f36567c546
commit e0450de6d9
Signed by: byterazor
GPG Key ID: EABDA0FD5981BC97
5 changed files with 132 additions and 0 deletions

View File

@ -137,6 +137,8 @@ add_executable(redmine-cli
src/Redmine-CLI/Command/IssueStatus.cpp src/Redmine-CLI/Command/IssueStatus.cpp
src/Redmine-CLI/Command/Issue.hpp src/Redmine-CLI/Command/Issue.hpp
src/Redmine-CLI/Command/Issue.cpp 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_link_libraries(redmine-cli redmine-api-cpp-static loguru CLI11 tableprinter::tableprinter)
target_include_directories(redmine-cli target_include_directories(redmine-cli

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <Redmine-CLI/Command/Upload.hpp>
#include <Redmine-CLI/Redmine.hpp>
#include "Redmine/API.hpp"
#include <string>
#include <tableprinter/tableprinter.hpp>
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;
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <CLI/App.hpp>
#include <Redmine/API.hpp>
#include <cstdint>
#include <string>
#include <vector>
#define LOGURU_WITH_STREAMS 1
#include <loguru.hpp>
#include <CLI/CLI.hpp>
// 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<std::string, outputType> 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

View File

@ -41,4 +41,5 @@ version_(nullptr)
project_ = std::make_unique<Command::Project>(this); project_ = std::make_unique<Command::Project>(this);
issueStatus_ = std::make_unique<Command::IssueStatus>(this); issueStatus_ = std::make_unique<Command::IssueStatus>(this);
issue_ = std::make_unique<Command::Issue>(this); issue_ = std::make_unique<Command::Issue>(this);
upload_ = std::make_unique<Command::Upload>(this);
} }

View File

@ -19,6 +19,7 @@
#include "Redmine-CLI/Command/IssueStatus.hpp" #include "Redmine-CLI/Command/IssueStatus.hpp"
#include "Redmine-CLI/Command/MyAccount.hpp" #include "Redmine-CLI/Command/MyAccount.hpp"
#include "Redmine-CLI/Command/Project.hpp" #include "Redmine-CLI/Command/Project.hpp"
#include "Redmine-CLI/Command/Upload.hpp"
#include "Redmine-CLI/Command/Version.hpp" #include "Redmine-CLI/Command/Version.hpp"
#include <CLI/App.hpp> #include <CLI/App.hpp>
#include <CLI/Option.hpp> #include <CLI/Option.hpp>
@ -68,6 +69,9 @@ namespace RedmineCLI
/// pointer to the issue subcommand /// pointer to the issue subcommand
std::unique_ptr<Command::Issue> issue_; std::unique_ptr<Command::Issue> issue_;
/// pointer to the upload subcommand
std::unique_ptr<Command::Upload> upload_;
public: public:
/** /**