Skip to content

Commit 35f28f8

Browse files
committed
Implement help text
1 parent 859e68f commit 35f28f8

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

src/CLIOptions.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "CLIOptions.hpp"
2+
#include "Utils/PrettyPrint.hpp"
23

34
#include <iostream>
45

@@ -11,20 +12,27 @@ namespace tsm::cli {
1112
{
1213
cxxopts::Options options("NetCDF Timestamp Mapper", "Maps timestamps and variables to netCDF files using sqlite3.");
1314

14-
options.add_options()
15-
("i,input-dir", "Input directory.", cxxopts::value<std::string>())
16-
("n,dataset-name", "Dataset name (no spaces).", cxxopts::value<std::string>())
17-
("o,output-dir", "Output directory.", cxxopts::value<std::string>())
15+
options.allow_unrecognised_options().add_options()
16+
("i,input-dir", "Input directory of netcdf files to scan.", cxxopts::value<std::string>())
17+
("n,dataset-name", "Dataset name (no spaces). Will also become the filename of the resulting database (with the .sqlite3 extension).", cxxopts::value<std::string>())
18+
("o,output-dir", "Output directory of the resulting database file. Make sure the user running the process has write priveleges to this folder!", cxxopts::value<std::string>())
1819
("regen-indices", "Regenerate indices.", cxxopts::value<bool>())
19-
("f,forecast", "Forecast dataset type.", cxxopts::value<bool>())
20-
("h,historical", "Historical dataset type.", cxxopts::value<bool>())
21-
("r,regex", "Regex to apply to input directory.", cxxopts::value<std::string>())
22-
("file-list", "Path to text file containing absolute file paths of netcdf files to be indexed.", cxxopts::value<std::string>())
23-
("dry-run", "Dry run", cxxopts::value<bool>())
20+
("f,forecast", "Forecast dataset type. INACTIVE AT THIS TIME.", cxxopts::value<bool>())
21+
("h,historical", "Indicates the dataset is historical in nature (i.e. not a forecast). In the future, there will be a -f flag to denote forecasts.", cxxopts::value<bool>())
22+
("r,regex", "Apply a regex pattern to the input directory to filter the scanned netcdf files.", cxxopts::value<std::string>())
23+
("file-list", "File containing absolute paths to netcdf files to be indexed. The format is 1 path per line (no line-ending commas, etc). Supported file extensions are: .txt, .diff, .ll.", cxxopts::value<std::string>())
24+
("dry-run", "Perform a dry-run of the tool; the list of scanned netcdf files will be output to the screen. No database changes will be made.", cxxopts::value<bool>())
2425
("help", "Print help.")
2526
;
2627

27-
return std::make_optional(options.parse(argc, argv));
28+
auto result{ options.parse(argc, argv) };
29+
30+
if (result.count("help")) {
31+
std::cout << options.help({""}) << std::endl;
32+
return std::nullopt;
33+
}
34+
35+
return std::make_optional(result);
2836
}
2937
catch (const cxxopts::OptionException &e)
3038
{
@@ -38,11 +46,6 @@ namespace tsm::cli {
3846
}
3947
}
4048

41-
/***********************************************************************************/
42-
void printHelp() {
43-
44-
}
45-
4649
/***********************************************************************************/
4750
std::string cleanRegexPattern(const std::string& inputPattern) {
4851
std::string cleaned = inputPattern;

src/CLIOptions.hpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ namespace tsm::cli {
1111
///
1212
[[nodiscard]] std::optional<cxxopts::ParseResult> parseCmdLineOptions(int argc, char** argv);
1313

14-
/***********************************************************************************/
15-
/// Print help message.
16-
void printHelp();
17-
1814
/***********************************************************************************/
1915
std::string cleanRegexPattern(const std::string& inputPattern);
2016

2117
/***********************************************************************************/
2218
struct [[nodiscard]] CLIOptions {
23-
explicit CLIOptions(const cxxopts::ParseResult& result) : InputDir{ result["input-dir"].as<std::string>() },
24-
DatasetName{ result["dataset-name"].as<std::string>() },
19+
explicit CLIOptions(const cxxopts::ParseResult& result) : InputDir{ result.count("input-dir") > 0 ? result["input-dir"].as<std::string>() : "" },
20+
DatasetName{ result.count("dataset-name") > 0 ? result["dataset-name"].as<std::string>() : "" },
2521
OutputDir{ result["output-dir"].as<std::string>() },
2622
RegexPattern{ result.count("regex") > 0 ? cleanRegexPattern(result["regex"].as<std::string>()) : ".*" },
2723
FileListPath{ result.count("file-list") > 0 ? result["file-list"].as<std::string>() : ""},

src/Utils/PrettyPrint.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <ostream>
4+
5+
namespace tsm::utils {
6+
7+
std::ostream& bold_on(std::ostream& os) {
8+
return os << "\e[1m";
9+
}
10+
11+
std::ostream& bold_off(std::ostream& os) {
12+
return os << "\e[0m";
13+
}
14+
15+
} //namespace tsm::utils

src/main.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ int main(int argc, char** argv) {
77

88
std::iostream::sync_with_stdio(false);
99

10-
const auto& result{ tsm::cli::parseCmdLineOptions(argc, argv) };
10+
auto result{ tsm::cli::parseCmdLineOptions(argc, argv) };
1111
if (!result) {
1212
return EXIT_FAILURE;
1313
}
1414

15-
if ((*result).count("help")) {
16-
tsm::cli::printHelp();
17-
return 0;
18-
}
19-
2015
const tsm::cli::CLIOptions opts{ *result };
2116
if (!opts.verify()) {
2217
return EXIT_FAILURE;

0 commit comments

Comments
 (0)