refactor
This commit is contained in:
parent
5ac2a24611
commit
eec3653c6b
@ -42,12 +42,12 @@
|
|||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
using action = std::function<exit_code(
|
using action = std::function<exit_code(
|
||||||
int, char **, const std::string &, const provider_type &,
|
std::vector<const char *>, const std::string &, const provider_type &,
|
||||||
const std::string &, std::string, std::string)>;
|
const std::string &, std::string, std::string)>;
|
||||||
|
|
||||||
struct option_hasher {
|
struct option_hasher {
|
||||||
auto operator()(const utils::cli::option &opt) const -> std::size_t {
|
auto operator()(const utils::cli::option &opt) const -> std::size_t {
|
||||||
return std::hash<std::string>()(opt[0u] + '|' + opt[1u]);
|
return std::hash<std::string>()(opt[0U] + '|' + opt[1U]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -75,14 +75,14 @@ static const std::unordered_map<utils::cli::option, action, option_hasher>
|
|||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto
|
||||||
perform_action(const utils::cli::option &opt, int argc, char *argv[],
|
perform_action(const utils::cli::option &opt, std::vector<const char *> args,
|
||||||
const std::string &data_directory, const provider_type &pt,
|
const std::string &data_directory, const provider_type &prov,
|
||||||
const std::string &unique_id, std::string user,
|
const std::string &unique_id, std::string user,
|
||||||
std::string password) -> exit_code {
|
std::string password) -> exit_code {
|
||||||
if (utils::cli::has_option(argc, argv, opt)) {
|
if (utils::cli::has_option(args, opt)) {
|
||||||
if (option_actions.find(opt) != option_actions.end()) {
|
if (option_actions.find(opt) != option_actions.end()) {
|
||||||
return option_actions.at(opt)(argc, argv, data_directory, pt, unique_id,
|
return option_actions.at(opt)(args, data_directory, prov, unique_id, user,
|
||||||
user, password);
|
password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,10 @@
|
|||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto
|
||||||
check_version(int, char *[], const std::string & /* data_directory */,
|
check_version(std::vector<const char *> /* args */,
|
||||||
const provider_type & /* pt */, const std::string &, std::string,
|
const std::string & /* data_directory */,
|
||||||
std::string) -> exit_code {
|
const provider_type & /* pt */, const std::string & /*unique_id*/,
|
||||||
|
std::string /*user*/, std::string /*password*/) -> exit_code {
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
|
|
||||||
// TODO need to updated way to check version
|
// TODO need to updated way to check version
|
||||||
|
@ -30,20 +30,22 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto display_config(std::vector<const char *> /* args */,
|
||||||
display_config(int, char *[], const std::string &data_directory,
|
const std::string &data_directory,
|
||||||
const provider_type &pt, const std::string &unique_id,
|
const provider_type &prov,
|
||||||
std::string user, std::string password) -> exit_code {
|
const std::string &unique_id,
|
||||||
lock_data lock(pt, unique_id);
|
std::string user, std::string password)
|
||||||
const auto res = lock.grab_lock(1u);
|
-> exit_code {
|
||||||
|
lock_data lock(prov, unique_id);
|
||||||
|
const auto res = lock.grab_lock(1U);
|
||||||
if (res == lock_result::success) {
|
if (res == lock_result::success) {
|
||||||
app_config config(pt, data_directory);
|
app_config config(prov, data_directory);
|
||||||
const auto cfg = config.get_json();
|
const auto cfg = config.get_json();
|
||||||
std::cout << 0 << std::endl;
|
std::cout << 0 << std::endl;
|
||||||
std::cout << cfg.dump(2) << std::endl;
|
std::cout << cfg.dump(2) << std::endl;
|
||||||
} else if (res == lock_result::locked) {
|
} else if (res == lock_result::locked) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).get_config();
|
client({"localhost", password, port, user}).get_config();
|
||||||
|
@ -31,24 +31,25 @@
|
|||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto
|
||||||
drive_information(int, char *[], const std::string &data_directory,
|
drive_information(std::vector<const char *> /* args */,
|
||||||
const provider_type &pt, const std::string &unique_id,
|
const std::string &data_directory, const provider_type &prov,
|
||||||
std::string user, std::string password) -> exit_code {
|
const std::string &unique_id, std::string user,
|
||||||
|
std::string password) -> exit_code {
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
|
|
||||||
lock_data lock(pt, unique_id);
|
lock_data lock(prov, unique_id);
|
||||||
const auto res = lock.grab_lock(1u);
|
const auto res = lock.grab_lock(1U);
|
||||||
if (res == lock_result::locked) {
|
if (res == lock_result::locked) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).get_drive_information();
|
client({"localhost", password, port, user}).get_drive_information();
|
||||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||||
std::cout << response.data.dump(2) << std::endl;
|
std::cout << response.data.dump(2) << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted."
|
std::cerr << app_config::get_provider_display_name(prov)
|
||||||
<< std::endl;
|
<< " is not mounted." << std::endl;
|
||||||
ret = exit_code::not_mounted;
|
ret = exit_code::not_mounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,19 +30,19 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto get(int argc, char *argv[],
|
[[nodiscard]] inline auto get(std::vector<const char *> args,
|
||||||
const std::string &data_directory,
|
const std::string &data_directory,
|
||||||
const provider_type &pt,
|
const provider_type &prov,
|
||||||
const std::string &unique_id, std::string user,
|
const std::string &unique_id, std::string user,
|
||||||
std::string password) -> exit_code {
|
std::string password) -> exit_code {
|
||||||
std::string data;
|
std::string data;
|
||||||
auto ret = utils::cli::parse_string_option(
|
auto ret = utils::cli::parse_string_option(
|
||||||
argc, argv, repertory::utils::cli::options::get_option, data);
|
args, repertory::utils::cli::options::get_option, data);
|
||||||
if (ret == exit_code::success) {
|
if (ret == exit_code::success) {
|
||||||
lock_data lock(pt, unique_id);
|
lock_data lock(prov, unique_id);
|
||||||
const auto res = lock.grab_lock(1);
|
const auto res = lock.grab_lock(1);
|
||||||
if (res == lock_result::success) {
|
if (res == lock_result::success) {
|
||||||
app_config config(pt, data_directory);
|
app_config config(prov, data_directory);
|
||||||
const auto value = config.get_value_by_name(data);
|
const auto value = config.get_value_by_name(data);
|
||||||
std::cout << (value.empty()
|
std::cout << (value.empty()
|
||||||
? static_cast<int>(
|
? static_cast<int>(
|
||||||
@ -51,8 +51,8 @@ namespace repertory::cli::actions {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << json({{"value", value}}).dump(2) << std::endl;
|
std::cout << json({{"value", value}}).dump(2) << std::endl;
|
||||||
} else if (res == lock_result::locked) {
|
} else if (res == lock_result::locked) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response = client({"localhost", password, port, user})
|
const auto response = client({"localhost", password, port, user})
|
||||||
.get_config_value_by_name(data);
|
.get_config_value_by_name(data);
|
||||||
|
@ -29,17 +29,16 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto get_directory_items(
|
||||||
get_directory_items(int argc, char *argv[], const std::string &data_directory,
|
std::vector<const char *> args, const std::string &data_directory,
|
||||||
const provider_type &pt, const std::string &,
|
const provider_type &prov, const std::string & /* unique_id */,
|
||||||
std::string user, std::string password) -> exit_code {
|
std::string user, std::string password) -> exit_code {
|
||||||
std::string data;
|
std::string data;
|
||||||
auto ret = utils::cli::parse_string_option(
|
auto ret = utils::cli::parse_string_option(
|
||||||
argc, argv, repertory::utils::cli::options::get_directory_items_option,
|
args, repertory::utils::cli::options::get_directory_items_option, data);
|
||||||
data);
|
|
||||||
if (ret == exit_code::success) {
|
if (ret == exit_code::success) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).get_directory_items(data);
|
client({"localhost", password, port, user}).get_directory_items(data);
|
||||||
|
@ -29,13 +29,15 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto get_pinned_files(std::vector<const char *> /* args */,
|
||||||
get_pinned_files(int, char *[], const std::string &data_directory,
|
const std::string &data_directory,
|
||||||
const provider_type &pt, const std::string &, std::string user,
|
const provider_type &prov,
|
||||||
|
const std::string & /* unique_id */,
|
||||||
|
std::string user,
|
||||||
std::string password) -> exit_code {
|
std::string password) -> exit_code {
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).get_pinned_files();
|
client({"localhost", password, port, user}).get_pinned_files();
|
||||||
|
@ -23,8 +23,8 @@
|
|||||||
#define INCLUDE_CLI_HELP_HPP_
|
#define INCLUDE_CLI_HELP_HPP_
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
template <typename drive> inline void help(int argc, char *argv[]) {
|
template <typename drive> inline void help(std::vector<const char *> args) {
|
||||||
drive::display_options(argc, argv);
|
drive::display_options(args);
|
||||||
std::cout << "Repertory options:" << std::endl;
|
std::cout << "Repertory options:" << std::endl;
|
||||||
std::cout << " -cv,--check_version Check daemon version "
|
std::cout << " -cv,--check_version Check daemon version "
|
||||||
"compatibility"
|
"compatibility"
|
||||||
|
@ -54,30 +54,30 @@ using remote_instance = repertory::remote_fuse::i_remote_instance;
|
|||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto
|
||||||
mount(int argc, char *argv[], std::string data_directory, int &mount_result,
|
mount(std::vector<const char *> args, std::string data_directory,
|
||||||
provider_type pt, const std::string &remote_host,
|
int &mount_result, provider_type prov, const std::string &remote_host,
|
||||||
std::uint16_t remote_port, const std::string &unique_id) -> exit_code {
|
std::uint16_t remote_port, const std::string &unique_id) -> exit_code {
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
|
|
||||||
lock_data lock(pt, unique_id);
|
lock_data lock(prov, unique_id);
|
||||||
const auto res = lock.grab_lock();
|
const auto res = lock.grab_lock();
|
||||||
if (res == lock_result::locked) {
|
if (res == lock_result::locked) {
|
||||||
ret = exit_code::mount_active;
|
ret = exit_code::mount_active;
|
||||||
std::cerr << app_config::get_provider_display_name(pt)
|
std::cerr << app_config::get_provider_display_name(prov)
|
||||||
<< " mount is already active" << std::endl;
|
<< " mount is already active" << std::endl;
|
||||||
} else if (res == lock_result::success) {
|
} else if (res == lock_result::success) {
|
||||||
const auto generate_config = utils::cli::has_option(
|
const auto generate_config = utils::cli::has_option(
|
||||||
argc, argv, utils::cli::options::generate_config_option);
|
args, utils::cli::options::generate_config_option);
|
||||||
if (generate_config) {
|
if (generate_config) {
|
||||||
app_config config(pt, data_directory);
|
app_config config(prov, data_directory);
|
||||||
if (pt == provider_type::remote) {
|
if (prov == provider_type::remote) {
|
||||||
config.set_enable_remote_mount(false);
|
config.set_enable_remote_mount(false);
|
||||||
config.set_is_remote_mount(true);
|
config.set_is_remote_mount(true);
|
||||||
config.set_remote_host_name_or_ip(remote_host);
|
config.set_remote_host_name_or_ip(remote_host);
|
||||||
config.set_remote_port(remote_port);
|
config.set_remote_port(remote_port);
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
std::cout << "Generated " << app_config::get_provider_display_name(pt)
|
std::cout << "Generated " << app_config::get_provider_display_name(prov)
|
||||||
<< " Configuration" << std::endl;
|
<< " Configuration" << std::endl;
|
||||||
std::cout << config.get_config_file_path() << std::endl;
|
std::cout << config.get_config_file_path() << std::endl;
|
||||||
ret = utils::file::is_file(config.get_config_file_path())
|
ret = utils::file::is_file(config.get_config_file_path())
|
||||||
@ -85,14 +85,13 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
|
|||||||
: exit_code::file_creation_failed;
|
: exit_code::file_creation_failed;
|
||||||
} else {
|
} else {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (utils::cli::has_option(argc, argv,
|
if (utils::cli::has_option(args, utils::cli::options::hidden_option)) {
|
||||||
utils::cli::options::hidden_option)) {
|
|
||||||
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
|
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
const auto drive_args =
|
const auto drive_args =
|
||||||
utils::cli::parse_drive_options(argc, argv, pt, data_directory);
|
utils::cli::parse_drive_options(args, prov, data_directory);
|
||||||
app_config config(pt, data_directory);
|
app_config config(prov, data_directory);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (config.get_enable_mount_manager() &&
|
if (config.get_enable_mount_manager() &&
|
||||||
not utils::is_process_elevated()) {
|
not utils::is_process_elevated()) {
|
||||||
@ -102,8 +101,8 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
|
|||||||
}
|
}
|
||||||
lock.release();
|
lock.release();
|
||||||
|
|
||||||
mount_result = utils::run_process_elevated(argc, argv);
|
mount_result = utils::run_process_elevated(args);
|
||||||
lock_data lock2(pt, unique_id);
|
lock_data lock2(prov, unique_id);
|
||||||
if (lock2.grab_lock() == lock_result::success) {
|
if (lock2.grab_lock() == lock_result::success) {
|
||||||
if (not lock2.set_mount_state(false, "", -1)) {
|
if (not lock2.set_mount_state(false, "", -1)) {
|
||||||
std::cerr << "failed to set mount state" << std::endl;
|
std::cerr << "failed to set mount state" << std::endl;
|
||||||
@ -114,15 +113,16 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
|
|||||||
return exit_code::mount_result;
|
return exit_code::mount_result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
std::cout << "Initializing " << app_config::get_provider_display_name(pt)
|
std::cout << "Initializing "
|
||||||
|
<< app_config::get_provider_display_name(prov)
|
||||||
<< (unique_id.empty() ? ""
|
<< (unique_id.empty() ? ""
|
||||||
: (pt == provider_type::s3)
|
: (prov == provider_type::s3)
|
||||||
? " [" + unique_id + ']'
|
? " [" + unique_id + ']'
|
||||||
: " [" + remote_host + ':' +
|
: " [" + remote_host + ':' +
|
||||||
std::to_string(remote_port) + ']')
|
std::to_string(remote_port) + ']')
|
||||||
<< " Drive" << std::endl;
|
<< " Drive" << std::endl;
|
||||||
if (pt == provider_type::remote) {
|
if (prov == provider_type::remote) {
|
||||||
std::uint16_t port = 0u;
|
std::uint16_t port{0U};
|
||||||
if (utils::get_next_available_port(config.get_api_port(), port)) {
|
if (utils::get_next_available_port(config.get_api_port(), port)) {
|
||||||
config.set_remote_host_name_or_ip(remote_host);
|
config.set_remote_host_name_or_ip(remote_host);
|
||||||
config.set_remote_port(remote_port);
|
config.set_remote_port(remote_port);
|
||||||
@ -155,7 +155,7 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
|
|||||||
config.set_is_remote_mount(false);
|
config.set_is_remote_mount(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto provider = create_provider(pt, config);
|
auto provider = create_provider(prov, config);
|
||||||
repertory_drive drive(config, lock, *provider);
|
repertory_drive drive(config, lock, *provider);
|
||||||
if (not lock.set_mount_state(true, "", -1)) {
|
if (not lock.set_mount_state(true, "", -1)) {
|
||||||
std::cerr << "failed to set mount state" << std::endl;
|
std::cerr << "failed to set mount state" << std::endl;
|
||||||
|
@ -31,23 +31,24 @@
|
|||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto
|
[[nodiscard]] inline auto
|
||||||
open_files(int, char *[], const std::string &data_directory,
|
open_files(std::vector<const char *> /* args */,
|
||||||
const provider_type &pt, const std::string &unique_id,
|
const std::string &data_directory, const provider_type &prov,
|
||||||
std::string user, std::string password) -> exit_code {
|
const std::string &unique_id, std::string user, std::string password)
|
||||||
|
-> exit_code {
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
lock_data lock(pt, unique_id);
|
lock_data lock(prov, unique_id);
|
||||||
const auto res = lock.grab_lock(1u);
|
const auto res = lock.grab_lock(1U);
|
||||||
if (res == lock_result::locked) {
|
if (res == lock_result::locked) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).get_open_files();
|
client({"localhost", password, port, user}).get_open_files();
|
||||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||||
std::cout << response.data.dump(2) << std::endl;
|
std::cout << response.data.dump(2) << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted."
|
std::cerr << app_config::get_provider_display_name(prov)
|
||||||
<< std::endl;
|
<< " is not mounted." << std::endl;
|
||||||
ret = exit_code::not_mounted;
|
ret = exit_code::not_mounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,17 +29,16 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto pin_file(int argc, char *argv[],
|
[[nodiscard]] inline auto
|
||||||
const std::string &data_directory,
|
pin_file(std::vector<const char *> args, const std::string &data_directory,
|
||||||
const provider_type &pt, const std::string &,
|
const provider_type &prov, const std::string & /* unique_id */,
|
||||||
std::string user, std::string password)
|
std::string user, std::string password) -> exit_code {
|
||||||
-> exit_code {
|
|
||||||
std::string data;
|
std::string data;
|
||||||
auto ret = utils::cli::parse_string_option(
|
auto ret = utils::cli::parse_string_option(
|
||||||
argc, argv, repertory::utils::cli::options::pin_file_option, data);
|
args, repertory::utils::cli::options::pin_file_option, data);
|
||||||
if (ret == exit_code::success) {
|
if (ret == exit_code::success) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).pin_file(data);
|
client({"localhost", password, port, user}).pin_file(data);
|
||||||
|
@ -29,17 +29,16 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto pinned_status(int argc, char *argv[],
|
[[nodiscard]] inline auto
|
||||||
const std::string &data_directory,
|
pinned_status(std::vector<const char *> args, const std::string &data_directory,
|
||||||
const provider_type &pt,
|
const provider_type &prov, const std::string & /*unique_id*/,
|
||||||
const std::string &, std::string user,
|
std::string user, std::string password) -> exit_code {
|
||||||
std::string password) -> exit_code {
|
|
||||||
std::string data;
|
std::string data;
|
||||||
auto ret = utils::cli::parse_string_option(
|
auto ret = utils::cli::parse_string_option(
|
||||||
argc, argv, repertory::utils::cli::options::pinned_status_option, data);
|
args, repertory::utils::cli::options::pinned_status_option, data);
|
||||||
if (ret == exit_code::success) {
|
if (ret == exit_code::success) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).pinned_status(data);
|
client({"localhost", password, port, user}).pinned_status(data);
|
||||||
|
@ -30,27 +30,27 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto set(int argc, char *argv[],
|
[[nodiscard]] inline auto set(std::vector<const char *> args,
|
||||||
const std::string &data_directory,
|
const std::string &data_directory,
|
||||||
const provider_type &pt,
|
const provider_type &prov,
|
||||||
const std::string &unique_id, std::string user,
|
const std::string &unique_id, std::string user,
|
||||||
std::string password) -> exit_code {
|
std::string password) -> exit_code {
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
auto data = utils::cli::parse_option(argc, argv, "-set", 2u);
|
auto data = utils::cli::parse_option(args, "-set", 2U);
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
data = utils::cli::parse_option(argc, argv, "--set", 2u);
|
data = utils::cli::parse_option(args, "--set", 2U);
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
ret = exit_code::invalid_syntax;
|
ret = exit_code::invalid_syntax;
|
||||||
std::cerr << "Invalid syntax for '-set'" << std::endl;
|
std::cerr << "Invalid syntax for '-set'" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == exit_code::success) {
|
if (ret == exit_code::success) {
|
||||||
lock_data lock(pt, unique_id);
|
lock_data lock(prov, unique_id);
|
||||||
const auto res = lock.grab_lock(1u);
|
const auto res = lock.grab_lock(1U);
|
||||||
if (res == lock_result::success) {
|
if (res == lock_result::success) {
|
||||||
app_config config(pt, data_directory);
|
app_config config(prov, data_directory);
|
||||||
const auto value = config.set_value_by_name(data[0u], data[1u]);
|
const auto value = config.set_value_by_name(data[0U], data[1U]);
|
||||||
const auto notFound = value.empty() && not data[1u].empty();
|
const auto notFound = value.empty() && not data[1U].empty();
|
||||||
ret = notFound ? exit_code::set_option_not_found : exit_code::success;
|
ret = notFound ? exit_code::set_option_not_found : exit_code::success;
|
||||||
std::cout << (notFound ? static_cast<int>(
|
std::cout << (notFound ? static_cast<int>(
|
||||||
rpc_response_type::config_value_not_found)
|
rpc_response_type::config_value_not_found)
|
||||||
@ -58,11 +58,11 @@ namespace repertory::cli::actions {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << json({{"value", value}}).dump(2) << std::endl;
|
std::cout << json({{"value", value}}).dump(2) << std::endl;
|
||||||
} else if (res == lock_result::locked) {
|
} else if (res == lock_result::locked) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response = client({"localhost", password, port, user})
|
const auto response = client({"localhost", password, port, user})
|
||||||
.set_config_value_by_name(data[0u], data[1u]);
|
.set_config_value_by_name(data[0U], data[1U]);
|
||||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||||
std::cout << response.data.dump(2) << std::endl;
|
std::cout << response.data.dump(2) << std::endl;
|
||||||
ret = response.response_type == rpc_response_type::config_value_not_found
|
ret = response.response_type == rpc_response_type::config_value_not_found
|
||||||
|
@ -26,13 +26,15 @@
|
|||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto status(int, char *[], const std::string &,
|
[[nodiscard]] inline auto status(std::vector<const char *> /* args */,
|
||||||
const provider_type &pt,
|
const std::string & /*data_directory*/,
|
||||||
const std::string &unique_id, std::string,
|
const provider_type &prov,
|
||||||
std::string) -> exit_code {
|
const std::string &unique_id,
|
||||||
|
std::string /* user */,
|
||||||
|
std::string /* password */) -> exit_code {
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
lock_data lock(pt, unique_id);
|
lock_data lock(prov, unique_id);
|
||||||
[[maybe_unused]] auto status = lock.grab_lock(10u);
|
[[maybe_unused]] auto status = lock.grab_lock(10U);
|
||||||
json mount_state;
|
json mount_state;
|
||||||
if (lock.get_mount_state(mount_state)) {
|
if (lock.get_mount_state(mount_state)) {
|
||||||
std::cout << mount_state.dump(2) << std::endl;
|
std::cout << mount_state.dump(2) << std::endl;
|
||||||
|
@ -29,14 +29,13 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto unmount(int, char *[],
|
[[nodiscard]] inline auto
|
||||||
const std::string &data_directory,
|
unmount(std::vector<const char *> /* args */, const std::string &data_directory,
|
||||||
const provider_type &pt, const std::string &,
|
const provider_type &prov, const std::string & /*unique_id*/,
|
||||||
std::string user, std::string password)
|
std::string user, std::string password) -> exit_code {
|
||||||
-> exit_code {
|
|
||||||
auto ret = exit_code::success;
|
auto ret = exit_code::success;
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response = client({"localhost", password, port, user}).unmount();
|
const auto response = client({"localhost", password, port, user}).unmount();
|
||||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||||
|
@ -29,17 +29,16 @@
|
|||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
[[nodiscard]] inline auto unpin_file(int argc, char *argv[],
|
[[nodiscard]] inline auto
|
||||||
const std::string &data_directory,
|
unpin_file(std::vector<const char *> args, const std::string &data_directory,
|
||||||
const provider_type &pt,
|
const provider_type &prov, const std::string & /*unique_id*/,
|
||||||
const std::string &, std::string user,
|
std::string user, std::string password) -> exit_code {
|
||||||
std::string password) -> exit_code {
|
|
||||||
std::string data;
|
std::string data;
|
||||||
auto ret = utils::cli::parse_string_option(
|
auto ret = utils::cli::parse_string_option(
|
||||||
argc, argv, repertory::utils::cli::options::unpin_file_option, data);
|
args, repertory::utils::cli::options::unpin_file_option, data);
|
||||||
if (ret == exit_code::success) {
|
if (ret == exit_code::success) {
|
||||||
auto port = app_config::default_api_port(pt);
|
auto port = app_config::default_api_port(prov);
|
||||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
utils::cli::get_api_authentication_data(user, password, port, prov,
|
||||||
data_directory);
|
data_directory);
|
||||||
const auto response =
|
const auto response =
|
||||||
client({"localhost", password, port, user}).unpin_file(data);
|
client({"localhost", password, port, user}).unpin_file(data);
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
#define INCLUDE_CLI_VERSION_HPP_
|
#define INCLUDE_CLI_VERSION_HPP_
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
template <typename drive> inline void version(int argc, char *argv[]) {
|
template <typename drive> inline void version(std::vector<const char *> args) {
|
||||||
std::cout << "Repertory core version: " << get_repertory_version()
|
std::cout << "Repertory core version: " << get_repertory_version()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << "Repertory Git revision: " << get_repertory_git_revision()
|
std::cout << "Repertory Git revision: " << get_repertory_git_revision()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
drive::display_version_information(argc, argv);
|
drive::display_version_information(args);
|
||||||
}
|
}
|
||||||
} // namespace repertory::cli::actions
|
} // namespace repertory::cli::actions
|
||||||
|
|
||||||
|
@ -38,6 +38,12 @@ public:
|
|||||||
|
|
||||||
virtual ~fuse_base();
|
virtual ~fuse_base();
|
||||||
|
|
||||||
|
public:
|
||||||
|
fuse_base(const fuse_base &) = delete;
|
||||||
|
fuse_base(fuse_base &&) = delete;
|
||||||
|
auto operator=(const fuse_base &) -> fuse_base & = delete;
|
||||||
|
auto operator=(fuse_base &&) -> fuse_base & = delete;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
app_config &config_;
|
app_config &config_;
|
||||||
|
|
||||||
@ -593,9 +599,9 @@ protected:
|
|||||||
virtual void shutdown();
|
virtual void shutdown();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void display_options(int argc, char *argv[]);
|
static void display_options(std::vector<const char *> args);
|
||||||
|
|
||||||
static void display_version_information(int argc, char *argv[]);
|
static void display_version_information(std::vector<const char *> args);
|
||||||
|
|
||||||
static auto unmount(const std::string &mount_location) -> int;
|
static auto unmount(const std::string &mount_location) -> int;
|
||||||
|
|
||||||
|
@ -36,6 +36,12 @@ public:
|
|||||||
|
|
||||||
~fuse_drive_base() override = default;
|
~fuse_drive_base() override = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
fuse_drive_base(const fuse_drive_base &) = delete;
|
||||||
|
fuse_drive_base(fuse_drive_base &&) = delete;
|
||||||
|
auto operator=(const fuse_drive_base &) -> fuse_drive_base & = delete;
|
||||||
|
auto operator=(fuse_drive_base &&) -> fuse_drive_base & = delete;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] auto access_impl(std::string api_path, int mask)
|
[[nodiscard]] auto access_impl(std::string api_path, int mask)
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
@ -193,9 +193,9 @@ public:
|
|||||||
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
static void display_options(int argc, char *argv[]) {}
|
static void display_options(std::vector<const char *> args) {}
|
||||||
|
|
||||||
static void display_version_information(int argc, char *argv[]) {}
|
static void display_version_information(std::vector<const char *> args) {}
|
||||||
};
|
};
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ namespace repertory {
|
|||||||
class app_config;
|
class app_config;
|
||||||
class i_provider;
|
class i_provider;
|
||||||
|
|
||||||
[[nodiscard]] auto create_provider(const provider_type &pt, app_config &config)
|
[[nodiscard]] auto create_provider(const provider_type &prov,
|
||||||
|
app_config &config)
|
||||||
-> std::unique_ptr<i_provider>;
|
-> std::unique_ptr<i_provider>;
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
@ -88,26 +88,28 @@ static const std::vector<option> option_list = {
|
|||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
void get_api_authentication_data(std::string &user, std::string &password,
|
void get_api_authentication_data(std::string &user, std::string &password,
|
||||||
std::uint16_t &port, const provider_type &pt,
|
std::uint16_t &port, const provider_type &prov,
|
||||||
const std::string &data_directory);
|
const std::string &data_directory);
|
||||||
|
|
||||||
[[nodiscard]] auto get_provider_type_from_args(int argc, char *argv[])
|
[[nodiscard]] auto get_provider_type_from_args(std::vector<const char *> args)
|
||||||
-> provider_type;
|
-> provider_type;
|
||||||
|
|
||||||
[[nodiscard]] auto has_option(int argc, char *argv[],
|
[[nodiscard]] auto has_option(std::vector<const char *> args,
|
||||||
const std::string &option_name) -> bool;
|
const std::string &option_name) -> bool;
|
||||||
|
|
||||||
[[nodiscard]] auto has_option(int argc, char *argv[], const option &opt)
|
[[nodiscard]] auto has_option(std::vector<const char *> args, const option &opt)
|
||||||
-> bool;
|
-> bool;
|
||||||
|
|
||||||
[[nodiscard]] auto parse_option(int argc, char *argv[],
|
[[nodiscard]] auto parse_option(std::vector<const char *> args,
|
||||||
const std::string &option_name,
|
const std::string &option_name,
|
||||||
std::uint8_t count) -> std::vector<std::string>;
|
std::uint8_t count) -> std::vector<std::string>;
|
||||||
|
|
||||||
[[nodiscard]] auto parse_string_option(int argc, char **argv, const option &opt,
|
[[nodiscard]] auto parse_string_option(std::vector<const char *> args,
|
||||||
std::string &value) -> exit_code;
|
const option &opt, std::string &value)
|
||||||
|
-> exit_code;
|
||||||
|
|
||||||
[[nodiscard]] auto parse_drive_options(int argc, char **argv, provider_type &pt,
|
[[nodiscard]] auto parse_drive_options(std::vector<const char *> args,
|
||||||
|
provider_type &prov,
|
||||||
std::string &data_directory)
|
std::string &data_directory)
|
||||||
-> std::vector<std::string>;
|
-> std::vector<std::string>;
|
||||||
} // namespace repertory::utils::cli
|
} // namespace repertory::utils::cli
|
||||||
|
@ -50,7 +50,7 @@ namespace repertory::utils {
|
|||||||
|
|
||||||
[[nodiscard]] auto is_process_elevated() -> bool;
|
[[nodiscard]] auto is_process_elevated() -> bool;
|
||||||
|
|
||||||
[[nodiscard]] auto run_process_elevated(int argc, char *argv[]) -> int;
|
[[nodiscard]] auto run_process_elevated(std::vector<const char *> args) -> int;
|
||||||
|
|
||||||
void set_last_error_code(DWORD errorCode);
|
void set_last_error_code(DWORD errorCode);
|
||||||
|
|
||||||
|
@ -160,21 +160,25 @@ void fuse_base::destroy_(void *ptr) {
|
|||||||
execute_void_callback(__FUNCTION__, [&]() { instance().destroy_impl(ptr); });
|
execute_void_callback(__FUNCTION__, [&]() { instance().destroy_impl(ptr); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void fuse_base::display_options([[maybe_unused]] int argc,
|
void fuse_base::display_options(
|
||||||
[[maybe_unused]] char *argv[]) {
|
[[maybe_unused]] std::vector<const char *> args) {
|
||||||
#if FUSE_USE_VERSION >= 30
|
#if FUSE_USE_VERSION >= 30
|
||||||
fuse_cmdline_help();
|
fuse_cmdline_help();
|
||||||
#else
|
#else
|
||||||
struct fuse_operations fuse_ops {};
|
struct fuse_operations fuse_ops {};
|
||||||
fuse_main(argc, argv, &fuse_ops, nullptr);
|
fuse_main(args.size(),
|
||||||
|
reinterpret_cast<char **>(const_cast<char **>(args.data())),
|
||||||
|
&fuse_ops, nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fuse_base::display_version_information(int argc, char *argv[]) {
|
void fuse_base::display_version_information(std::vector<const char *> args) {
|
||||||
struct fuse_operations fuse_ops {};
|
struct fuse_operations fuse_ops {};
|
||||||
fuse_main(argc, argv, &fuse_ops, nullptr);
|
fuse_main(args.size(),
|
||||||
|
reinterpret_cast<char **>(const_cast<char **>(args.data())),
|
||||||
|
&fuse_ops, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fuse_base::execute_callback(
|
auto fuse_base::execute_callback(
|
||||||
|
40
src/main.cpp
40
src/main.cpp
@ -39,12 +39,13 @@ std::size_t PROVIDER_INDEX{0U};
|
|||||||
auto main(int argc, char **argv) -> int {
|
auto main(int argc, char **argv) -> int {
|
||||||
repertory_init();
|
repertory_init();
|
||||||
|
|
||||||
|
std::vector<const char *> args(argv, argv + argc);
|
||||||
#ifdef REPERTORY_TESTING
|
#ifdef REPERTORY_TESTING
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (utils::cli::has_option(argc, argv, "--provider_index")) {
|
if (utils::cli::has_option(args, "--provider_index")) {
|
||||||
PROVIDER_INDEX = static_cast<std::size_t>(
|
PROVIDER_INDEX = static_cast<std::size_t>(
|
||||||
utils::string::to_uint64(
|
utils::string::to_uint64(
|
||||||
utils::cli::parse_option(argc, argv, "--provider_index", 1U)[0U]) +
|
utils::cli::parse_option(args, "--provider_index", 1U)[0U]) +
|
||||||
1U);
|
1U);
|
||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
@ -54,28 +55,25 @@ auto main(int argc, char **argv) -> int {
|
|||||||
delete_generated_files();
|
delete_generated_files();
|
||||||
#else
|
#else
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
argc++;
|
args.push_back("-h");
|
||||||
static std::string cmd(argv[0U]);
|
|
||||||
static std::vector<const char *> v({cmd.data(), "-h"});
|
|
||||||
argv = (char **)v.data();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto prov = utils::cli::get_provider_type_from_args(argc, argv);
|
auto prov = utils::cli::get_provider_type_from_args(args);
|
||||||
|
|
||||||
std::string data_directory;
|
std::string data_directory;
|
||||||
auto res = utils::cli::parse_string_option(
|
auto res = utils::cli::parse_string_option(
|
||||||
argc, argv, utils::cli::options::data_directory_option, data_directory);
|
args, utils::cli::options::data_directory_option, data_directory);
|
||||||
|
|
||||||
std::string password;
|
std::string password;
|
||||||
res = (res == exit_code::success)
|
res = (res == exit_code::success)
|
||||||
? utils::cli::parse_string_option(
|
? utils::cli::parse_string_option(
|
||||||
argc, argv, utils::cli::options::password_option, password)
|
args, utils::cli::options::password_option, password)
|
||||||
: res;
|
: res;
|
||||||
|
|
||||||
std::string user;
|
std::string user;
|
||||||
res = (res == exit_code::success)
|
res = (res == exit_code::success)
|
||||||
? utils::cli::parse_string_option(
|
? utils::cli::parse_string_option(
|
||||||
argc, argv, utils::cli::options::user_option, user)
|
args, utils::cli::options::user_option, user)
|
||||||
: res;
|
: res;
|
||||||
|
|
||||||
std::string remote_host;
|
std::string remote_host;
|
||||||
@ -84,7 +82,7 @@ auto main(int argc, char **argv) -> int {
|
|||||||
if ((res == exit_code::success) && (prov == provider_type::remote)) {
|
if ((res == exit_code::success) && (prov == provider_type::remote)) {
|
||||||
std::string data;
|
std::string data;
|
||||||
if ((res = utils::cli::parse_string_option(
|
if ((res = utils::cli::parse_string_option(
|
||||||
argc, argv, utils::cli::options::remote_mount_option, data)) ==
|
args, utils::cli::options::remote_mount_option, data)) ==
|
||||||
exit_code::success) {
|
exit_code::success) {
|
||||||
const auto parts = utils::string::split(data, ':');
|
const auto parts = utils::string::split(data, ':');
|
||||||
if (parts.size() != 2) {
|
if (parts.size() != 2) {
|
||||||
@ -102,7 +100,7 @@ auto main(int argc, char **argv) -> int {
|
|||||||
: data_directory,
|
: data_directory,
|
||||||
{utils::string::replace_copy(unique_id, ':', '_')});
|
{utils::string::replace_copy(unique_id, ':', '_')});
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
std::cerr << (e.what() ? e.what() : "Unable to parse port")
|
std::cerr << (e.what() == nullptr ? "Unable to parse port" : e.what())
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
res = exit_code::invalid_syntax;
|
res = exit_code::invalid_syntax;
|
||||||
}
|
}
|
||||||
@ -113,7 +111,7 @@ auto main(int argc, char **argv) -> int {
|
|||||||
#ifdef REPERTORY_ENABLE_S3
|
#ifdef REPERTORY_ENABLE_S3
|
||||||
if ((res == exit_code::success) && (prov == provider_type::s3)) {
|
if ((res == exit_code::success) && (prov == provider_type::s3)) {
|
||||||
std::string data;
|
std::string data;
|
||||||
if ((res = utils::cli::parse_string_option(argc, argv,
|
if ((res = utils::cli::parse_string_option(args,
|
||||||
utils::cli::options::name_option,
|
utils::cli::options::name_option,
|
||||||
data)) == exit_code::success) {
|
data)) == exit_code::success) {
|
||||||
unique_id = utils::string::trim(data);
|
unique_id = utils::string::trim(data);
|
||||||
@ -133,11 +131,11 @@ auto main(int argc, char **argv) -> int {
|
|||||||
|
|
||||||
int mount_result{};
|
int mount_result{};
|
||||||
if (res == exit_code::success) {
|
if (res == exit_code::success) {
|
||||||
if (utils::cli::has_option(argc, argv, utils::cli::options::help_option)) {
|
if (utils::cli::has_option(args, utils::cli::options::help_option)) {
|
||||||
cli::actions::help<repertory_drive>(argc, argv);
|
cli::actions::help<repertory_drive>(args);
|
||||||
} else if (utils::cli::has_option(argc, argv,
|
} else if (utils::cli::has_option(args,
|
||||||
utils::cli::options::version_option)) {
|
utils::cli::options::version_option)) {
|
||||||
cli::actions::version<repertory_drive>(argc, argv);
|
cli::actions::version<repertory_drive>(args);
|
||||||
} else {
|
} else {
|
||||||
res = exit_code::option_not_found;
|
res = exit_code::option_not_found;
|
||||||
for (std::size_t idx = 0U;
|
for (std::size_t idx = 0U;
|
||||||
@ -145,12 +143,12 @@ auto main(int argc, char **argv) -> int {
|
|||||||
(idx < utils::cli::options::option_list.size());
|
(idx < utils::cli::options::option_list.size());
|
||||||
idx++) {
|
idx++) {
|
||||||
res = cli::actions::perform_action(
|
res = cli::actions::perform_action(
|
||||||
utils::cli::options::option_list[idx], argc, argv, data_directory,
|
utils::cli::options::option_list[idx], args, data_directory, prov,
|
||||||
prov, unique_id, user, password);
|
unique_id, user, password);
|
||||||
}
|
}
|
||||||
if (res == exit_code::option_not_found) {
|
if (res == exit_code::option_not_found) {
|
||||||
res = cli::actions::mount(argc, argv, data_directory, mount_result,
|
res = cli::actions::mount(args, data_directory, mount_result, prov,
|
||||||
prov, remote_host, remote_port, unique_id);
|
remote_host, remote_port, unique_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,36 +43,33 @@ inline void create_comm(std::unique_ptr<intf_t> &comm, const config_t &config) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
auto create_provider(const provider_type &pt, app_config &config)
|
auto create_provider(const provider_type &prov, app_config &config)
|
||||||
-> std::unique_ptr<i_provider> {
|
-> std::unique_ptr<i_provider> {
|
||||||
static std::mutex mutex;
|
static std::mutex mutex;
|
||||||
mutex_lock lock(mutex);
|
mutex_lock lock(mutex);
|
||||||
|
|
||||||
static std::unique_ptr<i_http_comm> comm;
|
static std::unique_ptr<i_http_comm> comm;
|
||||||
|
|
||||||
switch (pt) {
|
switch (prov) {
|
||||||
case provider_type::sia: {
|
case provider_type::sia: {
|
||||||
create_comm<i_http_comm, curl_comm, host_config>(comm,
|
create_comm<i_http_comm, curl_comm, host_config>(comm,
|
||||||
config.get_host_config());
|
config.get_host_config());
|
||||||
return std::unique_ptr<i_provider>(
|
return std::make_unique<sia_provider>(config, *comm);
|
||||||
dynamic_cast<i_provider *>(new sia_provider(config, *comm)));
|
|
||||||
}
|
}
|
||||||
#if defined(REPERTORY_ENABLE_S3)
|
#if defined(REPERTORY_ENABLE_S3)
|
||||||
case provider_type::s3: {
|
case provider_type::s3: {
|
||||||
create_comm<i_http_comm, curl_comm, s3_config>(comm,
|
create_comm<i_http_comm, curl_comm, s3_config>(comm,
|
||||||
config.get_s3_config());
|
config.get_s3_config());
|
||||||
return std::unique_ptr<i_provider>(
|
return std::make_unique<s3_provider>(config, *comm);
|
||||||
dynamic_cast<i_provider *>(new s3_provider(config, *comm)));
|
|
||||||
}
|
}
|
||||||
#endif // defined(REPERTORY_ENABLE_S3)
|
#endif // defined(REPERTORY_ENABLE_S3)
|
||||||
case provider_type::encrypt: {
|
case provider_type::encrypt: {
|
||||||
return std::unique_ptr<i_provider>(
|
return std::make_unique<encrypt_provider>(config);
|
||||||
dynamic_cast<i_provider *>(new encrypt_provider(config)));
|
|
||||||
}
|
}
|
||||||
case provider_type::unknown:
|
case provider_type::unknown:
|
||||||
default:
|
default:
|
||||||
throw startup_exception("provider not supported: " +
|
throw startup_exception("provider not supported: " +
|
||||||
app_config::get_provider_display_name(pt));
|
app_config::get_provider_display_name(prov));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
@ -29,10 +29,10 @@
|
|||||||
|
|
||||||
namespace repertory::utils::cli {
|
namespace repertory::utils::cli {
|
||||||
void get_api_authentication_data(std::string &user, std::string &password,
|
void get_api_authentication_data(std::string &user, std::string &password,
|
||||||
std::uint16_t &port, const provider_type &pt,
|
std::uint16_t &port, const provider_type &prov,
|
||||||
const std::string &data_directory) {
|
const std::string &data_directory) {
|
||||||
const auto cfg_file_path = utils::path::combine(
|
const auto cfg_file_path = utils::path::combine(
|
||||||
data_directory.empty() ? app_config::default_data_directory(pt)
|
data_directory.empty() ? app_config::default_data_directory(prov)
|
||||||
: data_directory,
|
: data_directory,
|
||||||
{"config.json"});
|
{"config.json"});
|
||||||
|
|
||||||
@ -50,44 +50,45 @@ void get_api_authentication_data(std::string &user, std::string &password,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_provider_type_from_args(int argc, char *argv[]) -> provider_type {
|
[[nodiscard]] auto get_provider_type_from_args(std::vector<const char *> args)
|
||||||
|
-> provider_type {
|
||||||
#if defined(REPERTORY_ENABLE_S3)
|
#if defined(REPERTORY_ENABLE_S3)
|
||||||
if (has_option(argc, argv, options::s3_option)) {
|
if (has_option(args, options::s3_option)) {
|
||||||
return provider_type::s3;
|
return provider_type::s3;
|
||||||
}
|
}
|
||||||
#endif // defined(REPERTORY_ENABLE_S3)
|
#endif // defined(REPERTORY_ENABLE_S3)
|
||||||
if (has_option(argc, argv, options::remote_mount_option)) {
|
if (has_option(args, options::remote_mount_option)) {
|
||||||
return provider_type::remote;
|
return provider_type::remote;
|
||||||
}
|
}
|
||||||
if (has_option(argc, argv, options::encrypt_option)) {
|
if (has_option(args, options::encrypt_option)) {
|
||||||
return provider_type::encrypt;
|
return provider_type::encrypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider_type::sia;
|
return provider_type::sia;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto has_option(int argc, char *argv[], const std::string &option_name)
|
auto has_option(std::vector<const char *> args, const std::string &option_name)
|
||||||
-> bool {
|
-> bool {
|
||||||
auto ret = false;
|
return std::find_if(args.begin(), args.end(),
|
||||||
for (int i = 0; not ret && (i < argc); i++) {
|
[&option_name](const auto &value) -> bool {
|
||||||
ret = (option_name == argv[i]);
|
return option_name == value;
|
||||||
}
|
}) != args.end();
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto has_option(int argc, char *argv[], const option &opt) -> bool {
|
auto has_option(std::vector<const char *> args, const option &opt) -> bool {
|
||||||
return has_option(argc, argv, opt[0u]) || has_option(argc, argv, opt[1u]);
|
return has_option(args, opt[0U]) || has_option(args, opt[1U]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parse_option(int argc, char *argv[], const std::string &option_name,
|
auto parse_option(std::vector<const char *> args,
|
||||||
std::uint8_t count) -> std::vector<std::string> {
|
const std::string &option_name, std::uint8_t count)
|
||||||
|
-> std::vector<std::string> {
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> ret;
|
||||||
auto found = false;
|
auto found{false};
|
||||||
for (auto i = 0; not found && (i < argc); i++) {
|
for (std::size_t i = 0U; not found && (i < args.size()); i++) {
|
||||||
if ((found = (option_name == argv[i]))) {
|
if ((found = (option_name == args.at(i)))) {
|
||||||
if ((++i + count) <= argc) {
|
if ((++i + count) <= args.size()) {
|
||||||
while (count--) {
|
while ((count--) != 0U) {
|
||||||
ret.emplace_back(argv[i++]);
|
ret.emplace_back(args.at(i++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,90 +97,94 @@ auto parse_option(int argc, char *argv[], const std::string &option_name,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parse_string_option(int argc, char **argv, const option &opt,
|
auto parse_string_option(std::vector<const char *> args, const option &opt,
|
||||||
std::string &value) -> exit_code {
|
std::string &value) -> exit_code {
|
||||||
auto ret = exit_code::success;
|
exit_code ret{exit_code::success};
|
||||||
if (has_option(argc, argv, opt[0u]) || has_option(argc, argv, opt[1u])) {
|
if (has_option(args, opt.at(0U)) || has_option(args, opt.at(1U))) {
|
||||||
auto data = parse_option(argc, argv, opt[0u], 1u);
|
auto data = parse_option(args, opt.at(0U), 1U);
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
data = parse_option(argc, argv, opt[1u], 1u);
|
data = parse_option(args, opt.at(1U), 1U);
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
std::cerr << "Invalid syntax for '" << opt[0u] << "," << opt[1u] << '\''
|
std::cerr << "Invalid syntax for '" << opt.at(0U) << "," << opt.at(1U)
|
||||||
<< std::endl;
|
<< '\'' << std::endl;
|
||||||
ret = exit_code::invalid_syntax;
|
ret = exit_code::invalid_syntax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not data.empty()) {
|
if (not data.empty()) {
|
||||||
value = data[0u];
|
value = data.at(0U);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parse_drive_options(int argc, char **argv,
|
auto parse_drive_options(std::vector<const char *> args,
|
||||||
[[maybe_unused]] provider_type &pt,
|
[[maybe_unused]] provider_type &prov,
|
||||||
[[maybe_unused]] std::string &data_directory)
|
[[maybe_unused]] std::string &data_directory)
|
||||||
-> std::vector<std::string> {
|
-> std::vector<std::string> {
|
||||||
// Strip out options from command line
|
// Strip out options from command line
|
||||||
const auto &option_list = options::option_list;
|
const auto &option_list = options::option_list;
|
||||||
std::vector<std::string> drive_args;
|
std::vector<std::string> drive_args;
|
||||||
for (int i = 0; i < argc; i++) {
|
for (std::size_t i = 0U; i < args.size(); i++) {
|
||||||
const auto &a = argv[i];
|
const auto &arg = args.at(i);
|
||||||
if (std::find_if(option_list.begin(), option_list.end(),
|
if (std::find_if(option_list.begin(), option_list.end(),
|
||||||
[&a](const auto &pair) -> bool {
|
[&arg](const auto &pair) -> bool {
|
||||||
return ((pair[0] == a) || (pair[1] == a));
|
return ((pair[0] == arg) || (pair[1] == arg));
|
||||||
}) == option_list.end()) {
|
}) == option_list.end()) {
|
||||||
drive_args.emplace_back(argv[i]);
|
drive_args.emplace_back(args.at(i));
|
||||||
} else if ((std::string(argv[i]) == options::remote_mount_option[0]) ||
|
continue;
|
||||||
(std::string(argv[i]) == options::remote_mount_option[1])) {
|
|
||||||
i++;
|
|
||||||
} else if ((std::string(argv[i]) == options::data_directory_option[0]) ||
|
|
||||||
(std::string(argv[i]) == options::data_directory_option[1])) {
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((std::string(args.at(i)) == options::remote_mount_option[0U]) ||
|
||||||
|
(std::string(args.at(i)) == options::remote_mount_option[1U]) ||
|
||||||
|
(std::string(args.at(i)) == options::data_directory_option[0U]) ||
|
||||||
|
(std::string(args.at(i)) == options::data_directory_option[1U])
|
||||||
#ifdef REPERTORY_ENABLE_S3
|
#ifdef REPERTORY_ENABLE_S3
|
||||||
else if ((std::string(argv[i]) == options::name_option[0]) ||
|
|| (std::string(args.at(i)) == options::name_option[0U]) ||
|
||||||
(std::string(argv[i]) == options::name_option[1])) {
|
(std::string(args.at(i)) == options::name_option[1U])
|
||||||
i++;
|
|
||||||
}
|
|
||||||
#endif // REPERTORY_ENABLE_S3
|
#endif // REPERTORY_ENABLE_S3
|
||||||
|
) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
std::vector<std::string> fuse_flags_list;
|
std::vector<std::string> fuse_flags_list;
|
||||||
for (std::size_t i = 1; i < drive_args.size(); i++) {
|
for (std::size_t i = 1; i < drive_args.size(); i++) {
|
||||||
if (drive_args[i].find("-o") == 0) {
|
if (drive_args.at(i).find("-o") == 0) {
|
||||||
std::string options = "";
|
std::string options;
|
||||||
if (drive_args[i].size() == 2) {
|
if (drive_args[i].size() == 2) {
|
||||||
if ((i + 1) < drive_args.size()) {
|
if ((i + 1) < drive_args.size()) {
|
||||||
options = drive_args[++i];
|
options = drive_args.at(++i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
options = drive_args[i].substr(2);
|
options = drive_args.at(i).substr(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto fuse_option_list = utils::string::split(options, ',');
|
const auto fuse_option_list = utils::string::split(options, ',');
|
||||||
for (const auto &fuse_option : fuse_option_list) {
|
for (const auto &fuse_option : fuse_option_list) {
|
||||||
#if defined(REPERTORY_ENABLE_S3)
|
#if defined(REPERTORY_ENABLE_S3)
|
||||||
if (fuse_option.find("s3") == 0) {
|
if (fuse_option.find("s3") == 0) {
|
||||||
pt = provider_type::s3;
|
prov = provider_type::s3;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
#endif // defined(REPERTORY_ENABLE_S3)
|
#endif // defined(REPERTORY_ENABLE_S3)
|
||||||
if ((fuse_option.find("dd") == 0) ||
|
if ((fuse_option.find("dd") == 0) ||
|
||||||
(fuse_option.find("data_directory") == 0)) {
|
(fuse_option.find("data_directory") == 0)) {
|
||||||
const auto data = utils::string::split(fuse_option, '=');
|
const auto data = utils::string::split(fuse_option, '=');
|
||||||
if (data.size() == 2) {
|
if (data.size() == 2U) {
|
||||||
data_directory = data[1];
|
data_directory = data.at(1);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Invalid syntax for '-dd,--data_directory'"
|
std::cerr << "Invalid syntax for '-dd,--data_directory'"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
} else {
|
continue;
|
||||||
fuse_flags_list.push_back(fuse_option);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fuse_flags_list.push_back(fuse_option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,10 +199,12 @@ auto parse_drive_options(int argc, char **argv,
|
|||||||
utils::remove_element_from(new_drive_args, new_drive_args[i]);
|
utils::remove_element_from(new_drive_args, new_drive_args[i]);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
} else {
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
utils::remove_element_from(new_drive_args, new_drive_args[i]);
|
utils::remove_element_from(new_drive_args, new_drive_args[i]);
|
||||||
i--;
|
i--;
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,11 +144,12 @@ auto is_process_elevated() -> bool {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto run_process_elevated(int argc, char *argv[]) -> int {
|
auto run_process_elevated(std::vector<const char *> args) -> int {
|
||||||
std::cout << "Elevating Process" << std::endl;
|
std::cout << "Elevating Process" << std::endl;
|
||||||
std::string parameters = "-hidden";
|
std::string parameters = "-hidden";
|
||||||
for (int i = 1; i < argc; i++) {
|
for (std::size_t i = 1U; i < args.size(); i++) {
|
||||||
parameters += (parameters.empty() ? argv[i] : " " + std::string(argv[i]));
|
parameters +=
|
||||||
|
(parameters.empty() ? args.at(i) : " " + std::string(args.at(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
char full_path[MAX_PATH] = {0};
|
char full_path[MAX_PATH] = {0};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user