Skip to content

Commit ea4fc8a

Browse files
committed
app: separate types that might duplicate
1 parent 70679f5 commit ea4fc8a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

app/main.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ static bool no_arg(std::string_view fun){
5252
{"has_statx", fs_has_statx}
5353
};
5454

55-
using fs_function = std::function<std::variant<std::string, bool, int, char, long, pid_t, std::size_t>()>;
55+
using fs_function = std::function<std::variant<std::string, bool, int, char, long, std::size_t>()>;
5656

5757
std::unordered_map<std::string_view, fs_function> fs_function_map = {
5858
{"backend", []() { return fs_backend(); }},
5959
{"is_wsl", []() { return fs_is_wsl(); }},
60-
{"pid", []() { return fs_getpid(); }},
6160
{"pathsep", []() { return fs_pathsep(); }},
6261
{"cpp_lang", []() { return fs_cpp_lang(); }},
6362
{"c_lang", []() { return fs_c_lang(); }},
@@ -102,6 +101,8 @@ std::unordered_map<std::string_view, fs_function> fs_function_map = {
102101

103102
} else if (mbool.find(fun) != mbool.end())
104103
std::cout << mbool[fun]();
104+
else if (fun == "pid")
105+
std::cout << fs_getpid();
105106
else
106107
ok = false;
107108

@@ -118,11 +119,7 @@ static bool one_arg(std::string_view fun, std::string_view a1)
118119
std::error_code ec;
119120

120121
// each possible return type for the function
121-
using fs_one_arg_function = std::function<std::variant<std::string, bool, std::size_t, int
122-
#if uintmax_t != size_t
123-
, uintmax_t
124-
#endif
125-
>(std::string_view)>;
122+
using fs_one_arg_function = std::function<std::variant<std::string, bool, std::size_t, int>(std::string_view)>;
126123

127124
std::unordered_map<std::string_view, fs_one_arg_function> fs_one_arg_function_map = {
128125
{"lexically_normal", [](std::string_view a1) { return fs_lexically_normal(a1); }},
@@ -133,7 +130,6 @@ static bool one_arg(std::string_view fun, std::string_view a1)
133130
{"weakly_canonical", [](std::string_view a1) { return fs_canonical(a1, false); }},
134131
{"resolve", [](std::string_view a1) { return fs_resolve(a1, true); }},
135132
{"weakly_resolve", [](std::string_view a1) { return fs_resolve(a1, false); }},
136-
{"hard", [](std::string_view a1) { return fs_hard_link_count(a1); }},
137133
{"normal", [](std::string_view a1) { return fs_normal(a1); }},
138134
{"type", [](std::string_view a1) { return fs_filesystem_type(a1); }},
139135
{"is_reserved", [](std::string_view a1) { return fs_is_reserved(a1); }},
@@ -160,7 +156,6 @@ static bool one_arg(std::string_view fun, std::string_view a1)
160156
{"drop_slash", [](std::string_view a1) { return fs_drop_slash(a1); }},
161157
{"root_name", [](std::string_view a1) { return fs_root_name(a1); }},
162158
{"filename", [](std::string_view a1) { return fs_file_name(a1); }},
163-
{"file_size", [](std::string_view a1) { return fs_file_size(a1); }},
164159
{"is_absolute", [](std::string_view a1) { return fs_is_absolute(a1); }},
165160
{"is_exe", [](std::string_view a1) { return fs_is_exe(a1); }},
166161
{"is_exe_bin", [](std::string_view a1) { return fs_is_executable_binary(a1); }},
@@ -180,8 +175,6 @@ static bool one_arg(std::string_view fun, std::string_view a1)
180175
{"read_symlink", [](std::string_view a1) { return fs_read_symlink(a1); }},
181176
{"stem", [](std::string_view a1) { return fs_stem(a1); }},
182177
{"exists", [](std::string_view a1) { return fs_exists(a1); }},
183-
{"space_available", [](std::string_view a1) { return fs_space_available(a1); }},
184-
{"space_capacity", [](std::string_view a1) { return fs_space_capacity(a1); }},
185178
{"blksize", [](std::string_view a1) { return fs_get_blksize(a1); }},
186179
{"absolute", [](std::string_view a1) { return fs_absolute(a1, true); }},
187180
{"is_empty", [](std::string_view a1) { return fs_is_empty(a1); }},
@@ -190,6 +183,14 @@ static bool one_arg(std::string_view fun, std::string_view a1)
190183
{"which_all", [](std::string_view a1) { return fs_which(a1, "", true); }},
191184
};
192185

186+
std::map<std::string_view, std::function<std::uintmax_t(std::string_view)>> m1uintm =
187+
{
188+
{"file_size", [](std::string_view a1) { return fs_file_size(a1); }},
189+
{"space_available", [](std::string_view a1) { return fs_space_available(a1); }},
190+
{"space_capacity", [](std::string_view a1) { return fs_space_capacity(a1); }},
191+
{"hard_link_count", [](std::string_view a1) { return fs_hard_link_count(a1); }}
192+
};
193+
193194
bool ok = true;
194195

195196
auto it = fs_one_arg_function_map.find(fun);
@@ -209,6 +210,8 @@ static bool one_arg(std::string_view fun, std::string_view a1)
209210
else
210211
ok = false;
211212

213+
} else if (m1uintm.find(fun) != m1uintm.end()) {
214+
std::cout << m1uintm[fun](a1);
212215
} else if (fun == "modtime"){
213216

214217
#if defined(HAVE_CXX_FILESYSTEM) && defined(__cpp_lib_format) // C++20

0 commit comments

Comments
 (0)