refactor
This commit is contained in:
parent
28065c2c8e
commit
96c712ae9c
@ -72,59 +72,60 @@ auto main(int argc, char **argv) -> int {
|
||||
std::string remote_host;
|
||||
std::uint16_t remote_port{};
|
||||
std::string unique_id;
|
||||
if ((res == exit_code::success) && (prov == provider_type::remote)) {
|
||||
std::string data;
|
||||
res = utils::cli::parse_string_option(
|
||||
args, utils::cli::options::remote_mount_option, data);
|
||||
if (res == exit_code::success) {
|
||||
const auto parts = utils::string::split(data, ':', false);
|
||||
if (parts.size() != 2) {
|
||||
std::cerr << "Invalid syntax for host/port '-rm "
|
||||
"host:port,--remote_mount host:port'"
|
||||
<< std::endl;
|
||||
res = exit_code::invalid_syntax;
|
||||
} else {
|
||||
unique_id = parts.at(0U) + ':' + parts.at(1U);
|
||||
remote_host = parts.at(0U);
|
||||
try {
|
||||
remote_port = utils::string::to_uint16(parts.at(1U));
|
||||
data_directory = utils::path::combine(
|
||||
data_directory.empty() ? app_config::default_data_directory(prov)
|
||||
: data_directory,
|
||||
{utils::string::replace_copy(unique_id, ':', '_')});
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << (e.what() == nullptr ? "Unable to parse port" : e.what())
|
||||
if (res == exit_code::success) {
|
||||
if (prov == provider_type::remote) {
|
||||
std::string data;
|
||||
res = utils::cli::parse_string_option(
|
||||
args, utils::cli::options::remote_mount_option, data);
|
||||
if (res == exit_code::success) {
|
||||
const auto parts = utils::string::split(data, ':', false);
|
||||
if (parts.size() != 2) {
|
||||
std::cerr << "Invalid syntax for host/port '-rm "
|
||||
"host:port,--remote_mount host:port'"
|
||||
<< std::endl;
|
||||
res = exit_code::invalid_syntax;
|
||||
} else {
|
||||
unique_id = parts.at(0U) + ':' + parts.at(1U);
|
||||
remote_host = parts.at(0U);
|
||||
try {
|
||||
remote_port = utils::string::to_uint16(parts.at(1U));
|
||||
data_directory = utils::path::combine(
|
||||
data_directory.empty()
|
||||
? app_config::default_data_directory(prov)
|
||||
: data_directory,
|
||||
{utils::string::replace_copy(unique_id, ':', '_')});
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << (e.what() == nullptr ? "Unable to parse port"
|
||||
: e.what())
|
||||
<< std::endl;
|
||||
res = exit_code::invalid_syntax;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((res == exit_code::success) &&
|
||||
((prov == provider_type::s3) || (prov == provider_type::sia))) {
|
||||
std::string data;
|
||||
res = utils::cli::parse_string_option(
|
||||
args, utils::cli::options::name_option, data);
|
||||
if (res == exit_code::success) {
|
||||
unique_id = utils::string::trim(data);
|
||||
if (unique_id.empty()) {
|
||||
std::cerr << "Name of " << app_config::get_provider_name(prov)
|
||||
<< " instance not provided" << std::endl;
|
||||
res = exit_code::invalid_syntax;
|
||||
} else if (((prov == provider_type::s3) || (prov == provider_type::sia))) {
|
||||
std::string data;
|
||||
res = utils::cli::parse_string_option(
|
||||
args, utils::cli::options::name_option, data);
|
||||
if (res == exit_code::success) {
|
||||
unique_id = utils::string::trim(data);
|
||||
if (unique_id.empty()) {
|
||||
std::cerr << "Name of " << app_config::get_provider_name(prov)
|
||||
<< " instance not provided" << std::endl;
|
||||
res = exit_code::invalid_syntax;
|
||||
}
|
||||
} else if (res == exit_code::option_not_found &&
|
||||
prov == provider_type::sia) {
|
||||
unique_id = "default";
|
||||
res = exit_code::success;
|
||||
}
|
||||
} else if (res == exit_code::option_not_found &&
|
||||
prov == provider_type::sia) {
|
||||
unique_id = "default";
|
||||
res = exit_code::success;
|
||||
}
|
||||
|
||||
if (res == exit_code::success) {
|
||||
data_directory =
|
||||
data_directory.empty()
|
||||
? utils::path::combine(app_config::default_data_directory(prov),
|
||||
{unique_id})
|
||||
: utils::path::absolute(data_directory);
|
||||
if (res == exit_code::success) {
|
||||
data_directory =
|
||||
data_directory.empty()
|
||||
? utils::path::combine(app_config::default_data_directory(prov),
|
||||
{unique_id})
|
||||
: utils::path::absolute(data_directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user