From 320fd1f3f02d92996238d09d973e783cd8741ab9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 28 Apr 2025 21:54:11 +1200 Subject: [PATCH] hash --- src/main.cpp | 12 +++++------- src/utils/hash.cpp | 10 ++++++++++ src/utils/hash.hpp | 2 ++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 74e91a7..fed2d72 100644 --- a/src/main.cpp +++ b/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 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 << "Valid commands: "; for (const auto& command : commands) { - std::cerr << command << " "; + if (!command.empty() && command[0]!='_') + std::cerr << command << " "; } std::cerr << std::endl; return 1; diff --git a/src/utils/hash.cpp b/src/utils/hash.cpp index 8dfc47c..69de1ed 100644 --- a/src/utils/hash.cpp +++ b/src/utils/hash.cpp @@ -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 <