Skip to content

Commit

Permalink
Added -v,--version
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilor committed Jan 20, 2023
1 parent 569f743 commit 9cc4a34
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ae68135e4f74eed19a79fd982c7c4f98:email:ZGF0YTJAZW1haWwuY29t:ae68135e4f74eed19a79
```bash
$ md5sum input.txt
8998c19bb14b9af66ccdc79bed5818c4 input.txt
$ sha256 input.txt
$ sha256sum input.txt
99226b116e370a25130cce7e55fe3f813a0f3168c30e584de422e9f43b76fc1a input.txt
```

Expand Down
Binary file modified bin/hatofi
Binary file not shown.
33 changes: 27 additions & 6 deletions src/hatofi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@

int main(int argc, char** argv) {

// Application init
CLI::App app{"App description"};
const std::string BUILD_VERSION = "1.1";

/** Application init **/
CLI::App app{"HatofiDB - Hashmap To Filesystem Database\n > Created by Matthieu \"Vanilor\" Herbette\n > Find the repo at https://github.com/XVanilor/hatofi-db/\n"};
std::string data_dir = std::filesystem::current_path().string();
app.add_option("-d,--data-directory", data_dir, "Database directory")->required();
bool show_version = false;

CLI::App* startOpt = app.add_option_group("init");
auto nominalStartOpt = startOpt->add_option("-d,--data-directory", data_dir, "Database directory");
auto showVersionOpt = startOpt->add_flag("-v,--version", show_version, "Print binary version");

showVersionOpt->excludes(nominalStartOpt);
nominalStartOpt->excludes(showVersionOpt);

/** Database generation **/
CLI::App* genSub = app.add_subcommand("gen", "Generate Hatofi architecture based on config file");
Expand All @@ -28,7 +37,7 @@ int main(int argc, char** argv) {

/** Data Query */
CLI::App* querySub = app.add_subcommand("query", "Query data (exact or partial) from Hatofi DB");
CLI::App* queryOpt = querySub->add_option_group("queryOpt");
CLI::App* queryOpt = querySub->add_option_group("search_type");

bool queryPartialMatch{false};
bool queryExactMatch{true}; // Default is full-exact search because it's faster
Expand Down Expand Up @@ -56,11 +65,19 @@ int main(int argc, char** argv) {
return 1;
}
data_dir.clear();
printf("Data directory: %s\n", real_data_dir);
if(!show_version)
printf("Data directory: %s\n", real_data_dir);

HaDB db = HaDB(real_data_dir);

if(app.got_subcommand("gen"))
if(show_version)
{
printf("HatofiDB %s\n", BUILD_VERSION.c_str());
printf(" > Created by Matthieu \"Vanilor\" Herbette\n");
printf(" > Find the public repo at https://github.com/XVanilor/hatofi-db\n");
exit(0);
}
else if(app.got_subcommand("gen"))
{
log_info("Loading configuration...");
db.fromConfig(config_file);
Expand Down Expand Up @@ -96,6 +113,10 @@ int main(int argc, char** argv) {

printf("%s\n",task_uuid.c_str());
}
else
{
log_error("Please enter a command or use -h,--help");
}

return 0;
}

0 comments on commit 9cc4a34

Please sign in to comment.