This commit is contained in:
blankie 2024-01-02 23:40:41 +11:00
parent f3bb6ac62b
commit 229ffc2444
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -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")) {

30
subcommand_list.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <unistd.h>
#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
}
}

View File

@ -6,6 +6,7 @@ using Parser = blankie::cliparse::Parser;
#define HELP_TEXT &R"EOF(
Usage: %1$s [-C=<directory>] create
or %1$s [-C=<directory>] list
or %1$s [-C=<directory>] search <search query>
or %1$s [-C=<directory>] 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);