Skip to content

Commit 0b5f035

Browse files
committed
Return struct in check_manifest and fix future bug (default values for arguments in functions are only specified in the declaration, but not in the definition)
1 parent 7ed1f12 commit 0b5f035

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/utils.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <random>
88
#include <string>
99
#include <thread>
10+
#include "utils.hpp"
1011
#include "str_format.hpp"
1112
#include <dumb_json/djson.hpp>
1213

@@ -20,19 +21,7 @@ void sleep(int ms)
2021
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
2122
}
2223

23-
enum class Color
24-
{
25-
BLACK = 0,
26-
RED = 1,
27-
GREEN = 2,
28-
YELLOW = 3,
29-
BLUE = 4,
30-
MAGENTA = 5,
31-
CYAN = 6,
32-
WHITE = 7
33-
};
34-
35-
std::string style(std::string text, Color fore, Color back = Color::BLACK)
24+
std::string style(std::string text, Color fore, Color back)
3625
{
3726
// add fore and background ground color to text
3827
std::string ansi_text = kt::format_str("\x1B[3{}m", static_cast<int>(fore));
@@ -45,7 +34,7 @@ std::string style(std::string text, Color fore, Color back = Color::BLACK)
4534
return ansi_text.append(kt::format_str("{}\033[0m", text));
4635
}
4736

48-
std::filesystem::path find_upwards(std::string dir_name, int max_depth = 10)
37+
std::filesystem::path find_upwards(std::string dir_name, int max_depth)
4938
{
5039
auto path = std::filesystem::current_path() / std::filesystem::path(dir_name);
5140

@@ -79,24 +68,26 @@ std::vector<std::string> read_file(const std::filesystem::path& path)
7968
return lines;
8069
}
8170

82-
bool check_manifest(const std::filesystem::path& path)
71+
Manifest check_manifest(const std::filesystem::path& path)
8372
{
84-
bool game_ready = false;
73+
Manifest manifest{};
8574

8675
if (std::filesystem::exists(path))
8776
{
88-
auto manifest = read_file(path);
89-
auto json = std::accumulate(manifest.begin(), manifest.end(), std::string(""));
77+
auto file = read_file(path);
78+
auto json = std::accumulate(file.begin(), file.end(), std::string(""));
9079
if (auto n = dj::node_t::make(json))
9180
{
9281
dj::node_t& node = *n;
93-
game_ready = node["game_ready"].as<bool>();
82+
manifest.game_ready = node["game_ready"].as<bool>();
83+
manifest.duplicates = node["duplicates"].as<std::vector<int>>();
84+
manifest.files = node["files"].as<std::vector<std::string>>();
9485
}
9586
}
9687
else
9788
{
9889
std::cerr << "File not found: " << path.string() << '\n';
9990
}
10091

101-
return game_ready;
92+
return manifest;
10293
}

src/utils.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,12 @@ std::filesystem::path find_upwards(std::string dir_name, int max_depth = 10);
7070

7171
std::vector<std::string> read_file(const std::filesystem::path& path);
7272

73-
bool check_manifest(const std::filesystem::path& path);
73+
struct Manifest
74+
{
75+
Manifest() = default;
76+
std::vector<std::string> files{};
77+
std::vector<int> duplicates{};
78+
bool game_ready{};
79+
};
80+
81+
Manifest check_manifest(const std::filesystem::path& path);

0 commit comments

Comments
 (0)