aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/copy_cmd.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-09-05 13:02:27 +0200
committerGitHub Enterprise <[email protected]>2025-09-05 13:02:27 +0200
commit45b0307d42b22e04cee63467a8fdb898a2d8d552 (patch)
tree905b3eb62af89269be5b15f4c407d900ce86f7f3 /src/zen/cmds/copy_cmd.cpp
parentAvoid mutating executable paths when copying files during full service instal... (diff)
downloadarchived-zen-45b0307d42b22e04cee63467a8fdb898a2d8d552.tar.xz
archived-zen-45b0307d42b22e04cee63467a8fdb898a2d8d552.zip
refactor zen command return value handling (#487)
- Improvement: Use consistent language for command line argument parsing errors - Improvement: Changed zen command parsing errors to output help first and error last to make it easier to spot the error - Improvement: Refactor zen command return codes to conform to valid Linux range (0-255) kSuccess = 0, kOtherError = 1, kBadInput = 2, kOutOfMemory = 16, kOutOfDisk = 17, kAssertError = 70, kHttpOtherClientError = 80, kHttpCantConnectError = 81, kHttpNotFound = 66, // NotFound(404) kHttpUnauthorized = 77, // Unauthorized(401), kHttpSLLError = 82, kHttpForbidden = 83, // Forbidden(403) kHttpTimeout = 84, // RequestTimeout(408) kHttpConflict = 85, // Conflict(409) kHttpNoHost = 86, kHttpOtherServerError = 90, kHttpInternalServerError = 91, // InternalServerError(500) kHttpServiceUnavailable = 69, // ServiceUnavailable(503) kHttpBadGateway = 92, // BadGateway(502) kHttpGatewayTimeout = 93, // GatewayTimeout(504)
Diffstat (limited to 'src/zen/cmds/copy_cmd.cpp')
-rw-r--r--src/zen/cmds/copy_cmd.cpp35
1 files changed, 11 insertions, 24 deletions
diff --git a/src/zen/cmds/copy_cmd.cpp b/src/zen/cmds/copy_cmd.cpp
index 4e54f27bb..530661607 100644
--- a/src/zen/cmds/copy_cmd.cpp
+++ b/src/zen/cmds/copy_cmd.cpp
@@ -24,23 +24,23 @@ CopyCommand::CopyCommand()
CopyCommand::~CopyCommand() = default;
-int
+void
CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
ZEN_UNUSED(GlobalOptions);
- if (!ZenCmdBase::ParseOptions(argc, argv))
+ if (!ParseOptions(argc, argv))
{
- return 0;
+ return;
}
// Validate arguments
if (m_CopySource.empty())
- throw std::runtime_error("No source specified");
+ throw OptionParseException("'--source' is required", m_Options.help());
if (m_CopyTarget.empty())
- throw std::runtime_error("No target specified");
+ throw OptionParseException("'--target' is required", m_Options.help());
std::filesystem::path FromPath = m_CopySource;
std::filesystem::path ToPath = m_CopyTarget;
@@ -180,9 +180,7 @@ CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (Visitor.FailedFileCount)
{
- ZEN_CONSOLE_ERROR("{} file copy operations FAILED", Visitor.FailedFileCount);
-
- return 1;
+ throw std::runtime_error(fmt::format("{} file copy operations FAILED", Visitor.FailedFileCount));
}
}
else
@@ -194,27 +192,16 @@ CopyCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
zen::CopyFileOptions CopyOptions;
CopyOptions.EnableClone = !m_NoClone;
- try
+ zen::CreateDirectories(ToPath.parent_path());
+ if (zen::CopyFile(FromPath, ToPath, CopyOptions))
{
- zen::CreateDirectories(ToPath.parent_path());
- if (zen::CopyFile(FromPath, ToPath, CopyOptions))
- {
- ZEN_CONSOLE("Copy completed in {}", zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
- }
- else
- {
- throw std::logic_error("CopyFile failed in an unexpected way");
- }
+ ZEN_CONSOLE("Copy completed in {}", zen::NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
}
- catch (const std::exception& Ex)
+ else
{
- ZEN_CONSOLE_ERROR("Failed to copy '{}' to '{}': '{}'", FromPath, ToPath, Ex.what());
-
- return 1;
+ throw std::runtime_error(fmt::format("Failed to copy '{}' to '{}'", FromPath, ToPath));
}
}
-
- return 0;
}
} // namespace zen