hash
This commit is contained in:
parent
95e705b426
commit
320fd1f3f0
10
src/main.cpp
10
src/main.cpp
@ -85,6 +85,9 @@ std::string safearg(int argc, char *argv[], int index)
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
if (safearg(argc,argv,1) == "hash") return dropshell::hash_demo_raw(safearg(argc,argv,2));
|
||||
|
||||
try {
|
||||
// silently attempt to load the config file.
|
||||
dropshell::gConfig().load_config();
|
||||
@ -192,12 +195,6 @@ int main(int argc, char* argv[]) {
|
||||
return dropshell::main_commands::restore(argvec);
|
||||
}
|
||||
|
||||
if (cmd == "hash") {
|
||||
if (argc < 3) return die("Error: hash requires a directory to hash");
|
||||
dropshell::hash_demo(argvec[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// handle running a command.
|
||||
std::set<std::string> commands;
|
||||
dropshell::get_all_used_commands(commands);
|
||||
@ -230,6 +227,7 @@ int main(int argc, char* argv[]) {
|
||||
std::cerr << "Error: Unknown command '" << cmd << "'" << std::endl;
|
||||
std::cerr << "Valid commands: ";
|
||||
for (const auto& command : commands) {
|
||||
if (!command.empty() && command[0]!='_')
|
||||
std::cerr << command << " ";
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
|
@ -106,4 +106,14 @@ void hash_demo(const std::string & path)
|
||||
std::cout << "Hash: " << hash << " (took " << duration.count() << "ms)" << std::endl;
|
||||
}
|
||||
|
||||
int hash_demo_raw(const std::string & path)
|
||||
{
|
||||
if (!std::filesystem::exists(path)) {
|
||||
std::cout << 0 <<std::endl; return 1;
|
||||
}
|
||||
XXH64_hash_t hash = hash_directory_recursive(path);
|
||||
std::cout << hash << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
|
@ -12,6 +12,8 @@ namespace dropshell {
|
||||
|
||||
void hash_demo(const std::string & path);
|
||||
|
||||
int hash_demo_raw(const std::string & path);
|
||||
|
||||
} // namespace dropshell
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user