-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove project dependencies from cabin.toml closes #1074
- Loading branch information
Showing
9 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "Remove.hpp" | ||
|
||
#include "../Cli.hpp" | ||
#include "../Logger.hpp" | ||
#include "../Manifest.hpp" | ||
#include "../Rustify/Result.hpp" | ||
|
||
#include <cstdlib> | ||
#include <fmt/ranges.h> | ||
#include <fstream> | ||
#include <string> | ||
#include <toml.hpp> | ||
#include <toml11/types.hpp> | ||
#include <vector> | ||
|
||
namespace cabin { | ||
|
||
static Result<void> removeMain(CliArgsView args); | ||
|
||
const Subcmd REMOVE_CMD = // | ||
Subcmd{ "remove" } | ||
.setDesc("Remove dependencies from cabin.toml") | ||
.setArg(Arg{ "deps" } | ||
.setDesc("Dependencies to remove") | ||
.setRequired(true) | ||
.setVariadic(true)) | ||
.setMainFn(removeMain); | ||
|
||
static Result<void> | ||
removeMain(const CliArgsView args) { | ||
Ensure(!args.empty(), "`cabin remove` requires at least one argument"); | ||
|
||
std::vector<std::string_view> removedDeps = {}; | ||
const fs::path manifestPath = Try(findManifest()); | ||
auto data = toml::parse<toml::ordered_type_config>(manifestPath); | ||
auto& deps = data["dependencies"]; | ||
|
||
Ensure(!deps.is_empty(), "No dependencies to remove"); | ||
|
||
for (const std::string& dep : args) { | ||
if (deps.contains(dep)) { | ||
deps.as_table().erase(dep); | ||
removedDeps.push_back(dep); | ||
} else { | ||
// manifestPath needs to be converted to string | ||
// or it adds extra quotes around the path | ||
logger::warn( | ||
"Dependency `{}` not found in {}", dep, manifestPath.string() | ||
); | ||
} | ||
} | ||
|
||
if (!removedDeps.empty()) { | ||
std::ofstream out(manifestPath); | ||
out << data; | ||
logger::info( | ||
"Removed", "{} from {}", fmt::join(removedDeps, ", "), | ||
manifestPath.string() | ||
); | ||
} | ||
return Ok(); | ||
} | ||
|
||
} // namespace cabin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "../Cli.hpp" | ||
|
||
namespace cabin { | ||
|
||
extern const Subcmd REMOVE_CMD; | ||
|
||
} // namespace cabin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
test_description='Test the remove command' | ||
|
||
WHEREAMI=$(dirname "$(realpath "$0")") | ||
. $WHEREAMI/setup.sh | ||
|
||
test_expect_success 'cabin remove tbb mydep toml11' ' | ||
test_when_finished "rm -rf remove_test" && | ||
"$CABIN_BIN" new remove_test && | ||
cd remove_test && | ||
echo "[dependencies]" >> cabin.toml && | ||
echo "tbb = {}" >> cabin.toml && | ||
echo "toml11 = {}" >> cabin.toml && | ||
( | ||
"$CABIN_BIN" remove tbb mydep toml11 2>actual && | ||
! grep -q "tbb" cabin.toml && | ||
! grep -q "toml11" cabin.toml | ||
) && | ||
cat >expected <<-EOF && | ||
Warning: Dependency \`mydep\` not found in $WHEREAMI/trash directory.07-remove.sh/remove_test/cabin.toml | ||
Removed tbb, toml11 from $WHEREAMI/trash directory.07-remove.sh/remove_test/cabin.toml | ||
EOF | ||
test_cmp expected actual | ||
' | ||
test_done |