diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bdfea2..9de8303 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ add_link_options(${FLAGS}) add_executable(${PROJECT_NAME} main.cpp sqlite_wrapper.cpp database.cpp utils.cpp blankie/cliparse.cpp - subcommand_create.cpp subcommand_search.cpp subcommand_prune.cpp + subcommand_create.cpp subcommand_list.cpp subcommand_search.cpp subcommand_prune.cpp subcommand_info.cpp subcommand_delete.cpp subcommand_edit.cpp subcommand_get.cpp subcommand_set.cpp) set_target_properties(${PROJECT_NAME} PROPERTIES diff --git a/main.cpp b/main.cpp index 60b3737..a451695 100644 --- a/main.cpp +++ b/main.cpp @@ -70,6 +70,8 @@ void real_main(int argc, char** argv) { if (is("create")) { subcommand_create(parser); + } else if (is("list")) { + subcommand_list(parser); } else if (is("search")) { subcommand_search(parser); } else if (is("prune")) { diff --git a/subcommand_list.cpp b/subcommand_list.cpp new file mode 100644 index 0000000..642cb48 --- /dev/null +++ b/subcommand_list.cpp @@ -0,0 +1,30 @@ +#include + +#include "utils.h" +#include "database.h" + +#include "subcommands.h" + +void subcommand_list(const Parser& parser) { + if (parser.arguments.size() != 1) { + fprintf(stderr, HELP_TEXT, parser.program_name); + exit(1); + } + + Database db = Database::find(true); + Sqlite3Statement stmt(db.db, "SELECT path, source, description, miscinfo FROM memes"); + bool first_item = true; + + try { + db.db.exec(stmt, [&]() { + if (!first_item) { + write(1, "================================================================================\n", 81); + } + first_item = false; + + output_meme(stmt.column_text(0), stmt.column_text(1), stmt.column_text(2), stmt.column_text(3)); + }); + } catch (const Sqlite3Exception& e) { + // it'll be printed to the error log, so do nothing + } +} diff --git a/subcommands.h b/subcommands.h index b7f1bd4..79a4d2a 100644 --- a/subcommands.h +++ b/subcommands.h @@ -6,6 +6,7 @@ using Parser = blankie::cliparse::Parser; #define HELP_TEXT &R"EOF( Usage: %1$s [-C=] create + or %1$s [-C=] list or %1$s [-C=] search or %1$s [-C=] prune @@ -33,6 +34,7 @@ delimited by a null-byte )EOF"[1] void subcommand_create(const Parser& parser); +void subcommand_list(const Parser& parser); void subcommand_search(const Parser& parser); void subcommand_prune(const Parser& parser);