Add list
This commit is contained in:
parent
f3bb6ac62b
commit
229ffc2444
|
@ -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
|
||||
|
|
2
main.cpp
2
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")) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue