-
-
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.
* implement clean command * remove unused includes * Use concrete types instead of auto Co-authored-by: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> * s/std::filesystem/fs/ Co-authored-by: Ken Matsui <26405363+ken-matsui@users.noreply.github.com>
- Loading branch information
1 parent
11d2a27
commit 740b8a0
Showing
5 changed files
with
84 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef POAC_CMD_CLEAN_HPP_ | ||
#define POAC_CMD_CLEAN_HPP_ | ||
|
||
// external | ||
#include <structopt/app.hpp> | ||
|
||
// internal | ||
#include "poac/cmd/build.hpp" | ||
#include "poac/poac.hpp" | ||
|
||
namespace poac::cmd::clean { | ||
|
||
struct Options : structopt::sub_command { | ||
/// Whether or not to clean release artifacts | ||
Option<bool> release = false; | ||
/// Clean artifacts of the specified profile | ||
Option<String> profile; | ||
}; | ||
|
||
[[nodiscard]] Result<void> | ||
clean(const Options& opts); | ||
|
||
[[nodiscard]] Result<void> | ||
exec(const Options& opts); | ||
|
||
} // namespace poac::cmd::clean | ||
|
||
STRUCTOPT(poac::cmd::clean::Options, release, profile); | ||
|
||
#endif // POAC_CMD_CLEAN_HPP_ |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
add_poac_target(poac_cmd | ||
SOURCES | ||
build.cc | ||
clean.cc | ||
create.cc | ||
fmt.cc | ||
graph.cc | ||
|
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,44 @@ | ||
// external | ||
#include <spdlog/spdlog.h> // NOLINT(build/include_order) | ||
|
||
// internal | ||
#include "poac/cmd/clean.hpp" | ||
#include "poac/config.hpp" | ||
#include "poac/data/manifest.hpp" | ||
#include "poac/util/validator.hpp" | ||
|
||
namespace poac::cmd::clean { | ||
|
||
[[nodiscard]] Result<void> | ||
clean(const Options& opts) { | ||
const Option<String> profile = | ||
Try(util::validator::valid_profile(opts.profile, opts.release) | ||
.map_err(to_anyhow)); | ||
if (profile.has_value() && profile.value() != "debug" | ||
&& profile.value() != "release") { | ||
return Err<build::UnsupportedProfile>(profile.value()); | ||
} | ||
|
||
const Path path = profile.has_value() | ||
? config::path::output_dir / profile.value() | ||
: config::path::output_dir; | ||
|
||
spdlog::trace("Removing ./{}", path); | ||
|
||
if (fs::exists(path)) { | ||
log::status("Removing", fs::canonical(path).string()); | ||
fs::remove_all(path); | ||
} | ||
|
||
return Ok(); | ||
} | ||
|
||
[[nodiscard]] Result<void> | ||
exec(const Options& opts) { | ||
spdlog::trace("Checking if required config exists ..."); | ||
Try(util::validator::required_config_exists().map_err(to_anyhow)); | ||
|
||
return clean(opts); | ||
} | ||
|
||
} // namespace poac::cmd::clean |
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