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