Merge pull request #12 from davidallendj/project-validation

Add project validation check and corresponding CLI `--ignore-validation` option
This commit is contained in:
David Allen 2024-08-18 14:04:37 -06:00 committed by GitHub
commit f77d92cfef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 5 deletions

View file

@ -31,6 +31,7 @@ namespace gdpm::config{
bool enable_sync = true;
bool enable_cache = true;
bool skip_prompt = false;
bool ignore_validation = false;
bool enable_file_logging;
bool clean_temporary;

View file

@ -1,10 +1,7 @@
// Godot Package Manager (GPM)
#include "constants.hpp"
#include "log.hpp"
#include "config.hpp"
#include "package_manager.hpp"
#include "result.hpp"
#include <cstdlib>
@ -13,7 +10,13 @@ int main(int argc, char **argv){
using namespace gdpm::package_manager;
error error = initialize(argc, argv);
parse_arguments(argc, argv);
if(error.has_occurred()) {
log::error(error);
}
error = parse_arguments(argc, argv);
if(error.has_occurred()) {
log::error(error);
}
finalize();
return EXIT_SUCCESS;

View file

@ -147,6 +147,13 @@ namespace gdpm::package_manager{
.help("set verbosity level")
.nargs(nargs_pattern::optional);
program.add_argument("--ignore-validation")
.action([&](const auto&){ config.ignore_validation = true; })
.default_value(false)
.implicit_value(true)
.help("ignore checking if current directory is a Godot project")
.nargs(0);
install_command.add_description("install package(s)");
install_command.add_argument("packages")
.required()
@ -409,6 +416,13 @@ namespace gdpm::package_manager{
return log::error_rc(ec::ARGPARSE_ERROR, e.what());
}
/* Check if we're running in a directory with 'project.godot' file */
if (!config.ignore_validation) {
if(!std::filesystem::exists("project.godot")){
return error(ec::FILE_NOT_FOUND, "no 'project.godot' file found in current directory");
}
}
if(program.is_subcommand_used(install_command)){
action = action_e::install;
// if(install_command.is_used("packages"))