Super simple assert for now.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
parent
972d5f4db7
commit
4b4b99634c
@ -49,21 +49,10 @@ target_include_directories(dropshell PRIVATE
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/commands
|
${CMAKE_CURRENT_SOURCE_DIR}/src/commands
|
||||||
)
|
)
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
libassert
|
|
||||||
GIT_REPOSITORY https://github.com/jeremy-rifkin/libassert.git
|
|
||||||
GIT_TAG v2.1.5 # <HASH or TAG>
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(libassert)
|
|
||||||
target_link_libraries(dropshell libassert::assert)
|
|
||||||
|
|
||||||
# On windows copy libassert.dll to the same directory as the executable for your_target
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET dropshell POST_BUILD
|
TARGET dropshell POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
$<TARGET_FILE:libassert::assert>
|
|
||||||
$<TARGET_FILE_DIR:dropshell>
|
$<TARGET_FILE_DIR:dropshell>
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "services.hpp"
|
#include "services.hpp"
|
||||||
#include "servers.hpp"
|
#include "servers.hpp"
|
||||||
|
|
||||||
#include <libassert/assert.hpp>
|
#include <assert.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ bool autocomplete(const std::vector<std::string> &args)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(args.size() >= 3);
|
ASSERT(args.size() >= 3, "Invalid number of arguments");
|
||||||
std::string cmd = args[2];
|
std::string cmd = args[2];
|
||||||
|
|
||||||
// std::cout<<" cmd = ["<<cmd<<"]"<<std::endl;
|
// std::cout<<" cmd = ["<<cmd<<"]"<<std::endl;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
namespace dropshell
|
namespace dropshell
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@ namespace dropshell
|
|||||||
server_env_manager &server_env,
|
server_env_manager &server_env,
|
||||||
bool silent)
|
bool silent)
|
||||||
{
|
{
|
||||||
ASSERT(!local_path.empty() && !remote_path.empty());
|
ASSERT(!local_path.empty() && !remote_path.empty(), "Local or remote path not specified. Can't rsync.");
|
||||||
|
|
||||||
std::string rsync_cmd = "rsync --delete --mkpath -zrpc -e 'ssh -p " + server_env.get_SSH_PORT() + "' " +
|
std::string rsync_cmd = "rsync --delete --mkpath -zrpc -e 'ssh -p " + server_env.get_SSH_PORT() + "' " +
|
||||||
quote(local_path + "/") + " " +
|
quote(local_path + "/") + " " +
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "servers.hpp"
|
#include "servers.hpp"
|
||||||
#include "templates.hpp"
|
#include "templates.hpp"
|
||||||
|
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
#pragma TODO("Fix issues with Nuke below.")
|
#pragma TODO("Fix issues with Nuke below.")
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "servers.hpp"
|
#include "servers.hpp"
|
||||||
#include "services.hpp"
|
#include "services.hpp"
|
||||||
|
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "shared_commands.hpp"
|
#include "shared_commands.hpp"
|
||||||
#include "templates.hpp"
|
#include "templates.hpp"
|
||||||
|
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
namespace dropshell
|
namespace dropshell
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <libassert/assert.hpp>
|
#include <assert.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "service_runner.hpp"
|
#include "service_runner.hpp"
|
||||||
@ -457,7 +457,7 @@ bool service_runner::backup(bool silent) {
|
|||||||
std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_filename).string();
|
std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_filename).string();
|
||||||
|
|
||||||
// assert that the backup filename is valid - -_- appears exactly 3 times in local_backup_file_path.
|
// assert that the backup filename is valid - -_- appears exactly 3 times in local_backup_file_path.
|
||||||
ASSERT(3 == count_substring(magic_string, local_backup_file_path));
|
ASSERT(3 == count_substring(magic_string, local_backup_file_path), "Invalid backup filename");
|
||||||
|
|
||||||
{ // Run backup script
|
{ // Run backup script
|
||||||
cRemoteTempFolder remote_temp_folder(mServerEnv);
|
cRemoteTempFolder remote_temp_folder(mServerEnv);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
#include "utils/envmanager.hpp"
|
#include "utils/envmanager.hpp"
|
||||||
#include "utils/directories.hpp"
|
#include "utils/directories.hpp"
|
||||||
@ -105,7 +105,7 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void template_manager::list_templates() const {
|
void template_manager::list_templates() const {
|
||||||
ASSERT(mLoaded && mSources.size() > 0);
|
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||||
auto templates = get_template_list();
|
auto templates = get_template_list();
|
||||||
|
|
||||||
if (templates.empty()) {
|
if (templates.empty()) {
|
||||||
@ -128,7 +128,7 @@
|
|||||||
|
|
||||||
std::set<std::string> template_manager::get_template_list() const
|
std::set<std::string> template_manager::get_template_list() const
|
||||||
{
|
{
|
||||||
ASSERT(mLoaded && mSources.size() > 0);
|
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||||
std::set<std::string> templates;
|
std::set<std::string> templates;
|
||||||
for (const auto& source : mSources) {
|
for (const auto& source : mSources) {
|
||||||
auto source_templates = source->get_template_list();
|
auto source_templates = source->get_template_list();
|
||||||
@ -139,7 +139,7 @@
|
|||||||
|
|
||||||
bool template_manager::has_template(const std::string &template_name) const
|
bool template_manager::has_template(const std::string &template_name) const
|
||||||
{
|
{
|
||||||
ASSERT(mLoaded && mSources.size() > 0);
|
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||||
template_source_interface* source = get_source(template_name);
|
template_source_interface* source = get_source(template_name);
|
||||||
if (!source)
|
if (!source)
|
||||||
return false;
|
return false;
|
||||||
@ -148,7 +148,7 @@
|
|||||||
|
|
||||||
template_info template_manager::get_template_info(const std::string &template_name) const
|
template_info template_manager::get_template_info(const std::string &template_name) const
|
||||||
{
|
{
|
||||||
ASSERT(mLoaded && mSources.size() > 0);
|
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||||
template_source_interface* source = get_source(template_name);
|
template_source_interface* source = get_source(template_name);
|
||||||
if (source)
|
if (source)
|
||||||
return source->get_template_info(template_name);
|
return source->get_template_info(template_name);
|
||||||
@ -159,7 +159,7 @@
|
|||||||
|
|
||||||
bool template_manager::template_command_exists(const std::string &template_name, const std::string &command) const
|
bool template_manager::template_command_exists(const std::string &template_name, const std::string &command) const
|
||||||
{
|
{
|
||||||
ASSERT(mLoaded && mSources.size() > 0);
|
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||||
template_source_interface* source = get_source(template_name);
|
template_source_interface* source = get_source(template_name);
|
||||||
if (!source) {
|
if (!source) {
|
||||||
std::cerr << "Error: Template '" << template_name << "' not found" << std::endl;
|
std::cerr << "Error: Template '" << template_name << "' not found" << std::endl;
|
||||||
@ -249,9 +249,9 @@
|
|||||||
|
|
||||||
void template_manager::load_sources()
|
void template_manager::load_sources()
|
||||||
{
|
{
|
||||||
ASSERT(mSources.empty());
|
ASSERT(mSources.empty(), "Template manager already loaded (sources are not empty).");
|
||||||
ASSERT(gConfig().is_config_set());
|
ASSERT(gConfig().is_config_set(), "Config not set.");
|
||||||
ASSERT(!mLoaded);
|
ASSERT(!mLoaded, "Template manager already loaded.");
|
||||||
auto local_template_paths = gConfig().get_template_local_paths();
|
auto local_template_paths = gConfig().get_template_local_paths();
|
||||||
if (local_template_paths.empty())
|
if (local_template_paths.empty())
|
||||||
return;
|
return;
|
||||||
@ -285,7 +285,7 @@
|
|||||||
|
|
||||||
template_source_interface *template_manager::get_source(const std::string &template_name) const
|
template_source_interface *template_manager::get_source(const std::string &template_name) const
|
||||||
{
|
{
|
||||||
ASSERT(mLoaded && mSources.size() > 0);
|
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||||
for (const auto& source : mSources) {
|
for (const auto& source : mSources) {
|
||||||
if (source->has_template(template_name)) {
|
if (source->has_template(template_name)) {
|
||||||
return source.get();
|
return source.get();
|
||||||
|
11
src/utils/assert.hpp
Normal file
11
src/utils/assert.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef ASSERT_HPP
|
||||||
|
#define ASSERT_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#define ASSERT(condition, message) \
|
||||||
|
if (!(condition)) { \
|
||||||
|
std::cerr << "Assertion failed: " << message << std::endl; \
|
||||||
|
std::exit(1); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ASSERT_HPP
|
@ -6,7 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <libassert/assert.hpp>
|
#include "utils/assert.hpp"
|
||||||
|
|
||||||
#include "execute.hpp"
|
#include "execute.hpp"
|
||||||
#include "utils/utils.hpp"
|
#include "utils/utils.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user