Skip to content

Commit

Permalink
Added utilities to standardize help across cli tools. #370
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon McLean committed Jun 9, 2023
1 parent 0acff41 commit 84e6910
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
36 changes: 36 additions & 0 deletions apps/program_options_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#ifndef DISKANN_PROGRAM_OPTIONS_UTILS_CPP
#define DISKANN_PROGRAM_OPTIONS_UTILS_CPP

#include <string.h>

namespace program_options_utils
{
/**
* String appended to command-line tool help output to make the user aware that an argument is required
*/
inline const char required[] = "*";

const std::string make_required_param(const char *input)
{
return std::string(required).append(" ").append(input);
}

const std::string make_program_description(const char *executable_name, const char *description)
{
return std::string("\n")
.append(description)
.append("\n\n")
.append("Arguments with ")
.append(required)
.append(" are required")
.append("\n\n")
.append("Usage: ")
.append(executable_name)
.append(" [OPTIONS]");
}
} // namespace program_options_utils

#endif // DISKANN_PROGRAM_OPTIONS_UTILS_CPP
30 changes: 18 additions & 12 deletions apps/search_memory_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "index.h"
#include "memory_mapper.h"
#include "utils.h"
#include "program_options_utils.hpp"

namespace po = boost::program_options;

Expand Down Expand Up @@ -258,19 +259,27 @@ int main(int argc, char **argv)
bool print_all_recalls, dynamic, tags, show_qps_per_thread;
float fail_if_recall_below = 0.0f;

po::options_description desc{"Arguments"};
po::options_description desc{
program_options_utils::make_program_description("search_memory_index", "Searches in-memory DiskANN indexes")};
try
{
desc.add_options()("help,h", "Print information on arguments");
desc.add_options()("data_type", po::value<std::string>(&data_type)->required(), "data type <int8/uint8/float>");
desc.add_options()("dist_fn", po::value<std::string>(&dist_fn)->required(),
"distance function <l2/mips/fast_l2/cosine>");
desc.add_options()("help,h", "Print this information on arguments");
desc.add_options()("data_type", po::value<std::string>(&data_type)->required(),
program_options_utils::make_required_param("data type <int8/uint8/float>").c_str());
desc.add_options()(
"dist_fn", po::value<std::string>(&dist_fn)->required(),
program_options_utils::make_required_param("distance function <l2/mips/fast_l2/cosine>").c_str());
desc.add_options()("index_path_prefix", po::value<std::string>(&index_path_prefix)->required(),
"Path prefix to the index");
desc.add_options()("result_path", po::value<std::string>(&result_path)->required(),
"Path prefix for saving results of the queries");
program_options_utils::make_required_param("Path prefix to the index").c_str());
desc.add_options()(
"result_path", po::value<std::string>(&result_path)->required(),
program_options_utils::make_required_param("Path prefix for saving results of the queries").c_str());
desc.add_options()("query_file", po::value<std::string>(&query_file)->required(),
"Query file in binary format");
program_options_utils::make_required_param("Query file in binary format").c_str());
desc.add_options()("recall_at,K", po::value<uint32_t>(&K)->required(),
program_options_utils::make_required_param("Number of neighbors to be returned").c_str());
desc.add_options()("search_list,L", po::value<std::vector<uint32_t>>(&Lvec)->multitoken()->required(),
program_options_utils::make_required_param("List of L values of search").c_str());
desc.add_options()("filter_label", po::value<std::string>(&filter_label)->default_value(std::string("")),
"Filter Label for Filtered Search");
desc.add_options()("query_filters_file",
Expand All @@ -281,12 +290,9 @@ int main(int argc, char **argv)
"will consume memory 4 bytes per filter");
desc.add_options()("gt_file", po::value<std::string>(&gt_file)->default_value(std::string("null")),
"ground truth file for the queryset");
desc.add_options()("recall_at,K", po::value<uint32_t>(&K)->required(), "Number of neighbors to be returned");
desc.add_options()("print_all_recalls", po::bool_switch(&print_all_recalls),
"Print recalls at all positions, from 1 up to specified "
"recall_at value");
desc.add_options()("search_list,L", po::value<std::vector<uint32_t>>(&Lvec)->multitoken(),
"List of L values of search");
desc.add_options()("num_threads,T", po::value<uint32_t>(&num_threads)->default_value(omp_get_num_procs()),
"Number of threads used for building index (defaults to "
"omp_get_num_procs())");
Expand Down
2 changes: 1 addition & 1 deletion clang-format.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (NOT MSVC)
message(STATUS "Setting up `make format` and `make checkformat`")
# additional target to perform clang-format run, requires clang-format
# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES include/*.h python/src/*.cpp src/*.cpp apps/*.cpp)
file(GLOB_RECURSE ALL_SOURCE_FILES include/*.h python/src/*.cpp src/*.cpp apps/*.cpp apps/*.hpp)

message(status ${ALL_SOURCE_FILES})

Expand Down

0 comments on commit 84e6910

Please sign in to comment.