aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/workspaces_cmd.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-04-22 16:28:08 +0200
committerGitHub Enterprise <[email protected]>2025-04-22 16:28:08 +0200
commit732a1cb1e78abbabaa0d926e9b1e58a36538dc1b (patch)
tree08d47d333f68e2f99ec7ec922fa72dea4ee96dbc /src/zen/cmds/workspaces_cmd.cpp
parentxmake updatefrontend (diff)
downloadarchived-zen-732a1cb1e78abbabaa0d926e9b1e58a36538dc1b.tar.xz
archived-zen-732a1cb1e78abbabaa0d926e9b1e58a36538dc1b.zip
add cxxopts overload for parsing file paths from command line (#362)
Diffstat (limited to 'src/zen/cmds/workspaces_cmd.cpp')
-rw-r--r--src/zen/cmds/workspaces_cmd.cpp55
1 files changed, 26 insertions, 29 deletions
diff --git a/src/zen/cmds/workspaces_cmd.cpp b/src/zen/cmds/workspaces_cmd.cpp
index 5f3f8f7ca..2ddd0c73a 100644
--- a/src/zen/cmds/workspaces_cmd.cpp
+++ b/src/zen/cmds/workspaces_cmd.cpp
@@ -139,18 +139,16 @@ WorkspaceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
m_HostName = ResolveTargetHostSpec(m_HostName);
- std::filesystem::path SystemRootDir = StringToPath(m_SystemRootDir);
-
- if (SystemRootDir.empty())
+ if (m_SystemRootDir.empty())
{
- SystemRootDir = PickDefaultSystemRootDirectory();
- if (SystemRootDir.empty())
+ m_SystemRootDir = PickDefaultSystemRootDirectory();
+ if (m_SystemRootDir.empty())
{
throw zen::OptionParseException("unable to resolve system root directory");
}
}
- std::filesystem::path StatePath = SystemRootDir / "workspaces";
+ std::filesystem::path StatePath = m_SystemRootDir / "workspaces";
if (!ParseOptions(*SubOption, gsl::narrow<int>(SubCommandArguments.size()), SubCommandArguments.data()))
{
@@ -392,18 +390,20 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
m_HostName = ResolveTargetHostSpec(m_HostName);
- std::filesystem::path SystemRootDir = StringToPath(m_SystemRootDir);
-
- if (SystemRootDir.empty())
+ if (m_SystemRootDir.empty())
{
- SystemRootDir = PickDefaultSystemRootDirectory();
- if (SystemRootDir.empty())
+ m_SystemRootDir = PickDefaultSystemRootDirectory();
+ if (m_SystemRootDir.empty())
{
throw zen::OptionParseException("unable to resolve system root directory");
}
}
+ else
+ {
+ MakeSafeAbsolutePath(m_SystemRootDir);
+ }
- std::filesystem::path StatePath = SystemRootDir / "workspaces";
+ std::filesystem::path StatePath = m_SystemRootDir / "workspaces";
if (!ParseOptions(*SubOption, gsl::narrow<int>(SubCommandArguments.size()), SubCommandArguments.data()))
{
@@ -412,8 +412,7 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
if (SubOption == &m_CreateOptions)
{
- std::filesystem::path WorkspaceRoot = StringToPath(m_WorkspaceRoot);
- if (WorkspaceRoot.empty())
+ if (m_WorkspaceRoot.empty())
{
if (m_WorkspaceId.empty())
{
@@ -432,15 +431,15 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
ZEN_CONSOLE("Workspace {} does not exist", m_WorkspaceId);
return 0;
}
- WorkspaceRoot = WorkspaceConfig.RootPath;
+ m_WorkspaceRoot = WorkspaceConfig.RootPath;
}
else
{
- RemoveTrailingPathSeparator(WorkspaceRoot);
+ RemoveTrailingPathSeparator(m_WorkspaceRoot);
if (m_WorkspaceId.empty())
{
- m_WorkspaceId = Workspaces::PathToId(WorkspaceRoot).ToString();
- ZEN_CONSOLE("Using generated workspace id {} from path '{}'", m_WorkspaceId, WorkspaceRoot);
+ m_WorkspaceId = Workspaces::PathToId(m_WorkspaceRoot).ToString();
+ ZEN_CONSOLE("Using generated workspace id {} from path '{}'", m_WorkspaceId, m_WorkspaceRoot);
}
else
{
@@ -449,25 +448,23 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
throw zen::OptionParseException(fmt::format("workspace id '{}' is invalid", m_WorkspaceId));
}
}
- if (Workspaces::AddWorkspace(Log(), StatePath, {.Id = Oid::FromHexString(m_WorkspaceId), .RootPath = WorkspaceRoot}))
+ if (Workspaces::AddWorkspace(Log(), StatePath, {.Id = Oid::FromHexString(m_WorkspaceId), .RootPath = m_WorkspaceRoot}))
{
- ZEN_CONSOLE("Created workspace {} using root path '{}'", m_WorkspaceId, WorkspaceRoot);
+ ZEN_CONSOLE("Created workspace {} using root path '{}'", m_WorkspaceId, m_WorkspaceRoot);
}
else
{
- ZEN_CONSOLE("Using existing workspace {} with root path '{}'", m_WorkspaceId, WorkspaceRoot);
+ ZEN_CONSOLE("Using existing workspace {} with root path '{}'", m_WorkspaceId, m_WorkspaceRoot);
}
}
- std::filesystem::path SharePath = StringToPath(m_SharePath);
-
- RemoveLeadingPathSeparator(SharePath);
- RemoveTrailingPathSeparator(SharePath);
+ RemoveLeadingPathSeparator(m_SharePath);
+ RemoveTrailingPathSeparator(m_SharePath);
if (m_ShareId.empty())
{
- m_ShareId = Workspaces::PathToId(SharePath).ToString();
- ZEN_CONSOLE("Using generated share id {}, for path '{}'", m_ShareId, SharePath);
+ m_ShareId = Workspaces::PathToId(m_SharePath).ToString();
+ ZEN_CONSOLE("Using generated share id {}, for path '{}'", m_ShareId, m_SharePath);
}
if (Oid::TryFromHexString(m_ShareId) == Oid::Zero)
@@ -476,8 +473,8 @@ WorkspaceShareCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char**
}
if (Workspaces::AddWorkspaceShare(Log(),
- WorkspaceRoot,
- {.Id = Oid::FromHexString(m_ShareId), .SharePath = SharePath, .Alias = m_Alias}))
+ m_WorkspaceRoot,
+ {.Id = Oid::FromHexString(m_ShareId), .SharePath = m_SharePath, .Alias = m_Alias}))
{
if (!m_HostName.empty())
{