Skip to content

Commit

Permalink
Merge branch 'TDT-51_improve_docs' into 'main'
Browse files Browse the repository at this point in the history
Tdt 51 improve docs - more improvement to come but this is a good start on the ReadMe

See merge request soldev/cyberdev/lightgrep!15
  • Loading branch information
sf-jonstewart committed Apr 17, 2024
2 parents 05b4c25 + 23540fd commit 4f86956
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 15 deletions.
287 changes: 281 additions & 6 deletions README.md

Large diffs are not rendered by default.

Binary file added documentation/LightgrepSyntaxCheatSheet.pdf
Binary file not shown.
Binary file added documentation/gifs/binary_file.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/gifs/context.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/gifs/lightgrep_search.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions documentation/images/cat_or_code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions src/cmd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ namespace po = boost::program_options;
namespace fs = std::filesystem;

void printVersion(std::ostream& out) {
const std::string buildDate(__DATE__);
// ANSI C now defines __DATE__ as 11-char string of MMM DD YYYY, but double-check
const std::string year = buildDate.size() == 11 && buildDate[7] == '2' ? buildDate.substr(7, 4): "2024";
out << "lightgrep " << VERSION << '\n'
<< "Copyright (c) 2010-2017, Stroz Friedberg, LLC\n"
"Built " << __DATE__ << std::endl;
<< "Copyright (c) 2010-" << year << ", Stroz Friedberg, LLC\n"
"Built " << buildDate << std::endl;
}

void printUsage(std::ostream& out) {
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/optparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void parse_opts(int argc, const char* const * argv,
// Command selection options
po::options_description general("Command selection");
general.add_options()
("command,c", po::value<std::string>(&command)->value_name("CMD")->default_value("search"), "command to perform [search|graph|prog|samp|validate|analyze]")
("command,c", po::value<std::string>(&command)->value_name("CMD")->default_value("search"), "command to perform [search|graph|prog|sample|validate|analyze]")
("help", "display this help message")
("list-encodings", "list known encodings")
("version,V", "print version information and exit")
Expand All @@ -64,7 +64,7 @@ void parse_opts(int argc, const char* const * argv,
pats.add_options()
("keywords,k", po::value<std::vector<std::string>>(&opts.KeyFiles)->composing()->value_name("FILE"), "path to keywords file")
("pattern,p", po::value<std::vector<std::string>>(&opts.CmdLinePatterns)->composing()->value_name("PATTERN"), "a keyword on the command-line")
("encoding,e", po::value<std::vector<std::string>>(&opts.Encodings)->default_value(std::vector<std::string>{"ASCII"}, "ASCII")->composing()->value_name("ENCODING"), "encoding to use (e.g., ASCII, UTF-8)")
("encoding,e", po::value<std::vector<std::string>>(&opts.Encodings)->default_value(std::vector<std::string>{"US-ASCII"}, "US-ASCII")->composing()->value_name("ENCODING"), "encoding to use (e.g., US-ASCII, UTF-8)")
("ignore-case,i", "ignore case distinctions")
("fixed-strings,F", "interpret patterns as fixed strings")
;
Expand Down Expand Up @@ -147,8 +147,8 @@ void parse_opts(int argc, const char* const * argv,
std::map<std::string,Options::CommandTypes> cmds;
cmds.insert(std::make_pair("search", Options::SEARCH));
cmds.insert(std::make_pair("graph", Options::GRAPH));
cmds.insert(std::make_pair("prog", Options::PROGRAM));
cmds.insert(std::make_pair("samp", Options::SAMPLES));
cmds.insert(std::make_pair("program", Options::PROGRAM));
cmds.insert(std::make_pair("sample", Options::SAMPLES));
cmds.insert(std::make_pair("validate", Options::VALIDATE));
cmds.insert(std::make_pair("analyze", Options::ANALYZE));

Expand Down
6 changes: 3 additions & 3 deletions test/test_optparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ TEST_CASE("mmapIncompatibleWithReadFromStdin") {
}

TEST_CASE("sampleOptions") {
const char* argv[] = {"lightgrep", "-c", "samp", "--program-file", "test-prog.txt", "3", "5"};
const char* argv[] = {"lightgrep", "-c", "sample", "--program-file", "test-prog.txt", "3", "5"};
Options opts;

po::options_description desc;
Expand All @@ -193,7 +193,7 @@ TEST_CASE("readFromStdinWhenNoInputsProvided") {
}

TEST_CASE("tooManyPositionalArguments") {
const char* argv[] = {"lightgrep", "-c", "samp", "--program-file", "test-prog.txt", "3", "5", "this", "is", "too", "many", "positional", "args"};
const char* argv[] = {"lightgrep", "-c", "sample", "--program-file", "test-prog.txt", "3", "5", "this", "is", "too", "many", "positional", "args"};
Options opts;

po::options_description desc;
Expand Down Expand Up @@ -262,4 +262,4 @@ TEST_CASE("Negative context option should align with grep behavior") {
}


}
}

0 comments on commit 4f86956

Please sign in to comment.