From 133f7f9c2ad2e4edb1f3485467c505a41dcdaa37 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 30 Aug 2018 16:54:34 +0200 Subject: [PATCH] added feature to print help --- CMakeLists.txt | 2 +- README.md | 9 ++++++++- src/whyblock.cpp | 25 +++++++++++++++++++------ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20aff84..e2f8f5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (whyblocked - VERSION 0.4.0 + VERSION 0.5.0 LANGUAGES CXX ) diff --git a/README.md b/README.md index 8092ca2..c8df819 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,17 @@ It has a text interface and uses a SQLite-database. ```PLAIN $ whyblocked -This is whyblocked 0.4.0. +This is whyblocked 0.4.1. Type add, remove, view or details. Or just the first letter. Type quit or q to quit the program. : add User or instance: @tastytea@soc.ialis.me Blocked(b) or silenced(s): b Reason: Too nice +@tastytea@soc.ialis.me added. Add receipt? [y/n] y URL: https://tastytea.de/ +Receipt added. Add receipt? [y/n] n : view Blocked: @tastytea@soc.ialis.me because: Too nice @@ -28,6 +30,11 @@ Receipts: https://tastytea.de/ : remove User or instance: @tastytea@soc.ialis.me +@tastytea@soc.ialis.me removed. +: view +: details +User or instance: @tastytea@soc.ialis.me +@tastytea@soc.ialis.me is not in the database. : quit ``` diff --git a/src/whyblock.cpp b/src/whyblock.cpp index e5b7c5e..0fc946e 100644 --- a/src/whyblock.cpp +++ b/src/whyblock.cpp @@ -24,7 +24,7 @@ string get_filepath() filepath = xdgDataHome(&xdg); xdgWipeHandle(&xdg); - filepath += "/whyblock"; + filepath += "/whyblocked"; if (!fs::exists(filepath)) { fs::create_directory(filepath); @@ -33,13 +33,20 @@ string get_filepath() if (!fs::exists(filepath)) { sqlite::connection con(filepath); - sqlite::execute(con, "CREATE TABLE blocks(user TEXT PRIMARY KEY, blocked INTEGER, reason TEXT);", true); + sqlite::execute(con, "CREATE TABLE blocks(user TEXT PRIMARY KEY, " + "blocked INTEGER, reason TEXT);", true); sqlite::execute(con, "CREATE TABLE urls(user TEXT, url TEXT);", true); } return filepath; } +const void print_help() +{ + cout << "Type add, remove, view or details. Or just the first letter.\n"; + cout << "Type help or h to show this help. Type quit or q to quit the program.\n"; +} + int main(int argc, char *argv[]) { try @@ -48,8 +55,7 @@ int main(int argc, char *argv[]) bool keeprunning = true; cout << "This is whyblocked " << global::version << ".\n"; - cout << "Type add, remove, view or details. Or just the first letter.\n"; - cout << "Type quit or q to quit the program.\n"; + print_help(); while (keeprunning) { string answer = ""; @@ -84,6 +90,7 @@ int main(int argc, char *argv[]) sqlite::execute ins(con, "INSERT INTO blocks VALUES(?, ?, ?);"); ins % user % blocked % reason; ins(); + cout << user << " added.\n"; while (true) { @@ -98,6 +105,7 @@ int main(int argc, char *argv[]) sqlite::execute ins(con, "INSERT INTO urls VALUES(?, ?);"); ins % user % url; ins(); + cout << "Receipt added.\n"; } else if (answer[0] == 'n' || answer[0] == 'N') { @@ -123,7 +131,7 @@ int main(int argc, char *argv[]) rm_urls % user; rm_blocks(); rm_urls(); - + cout << user << " removed.\n"; break; } case 'v': @@ -152,7 +160,8 @@ int main(int argc, char *argv[]) cout << "User or instance: "; cin >> answer; { - sqlite::query q(con, "SELECT * FROM blocks WHERE user = \'" + answer + "\';"); + sqlite::query q(con, "SELECT * FROM blocks WHERE " + "user = \'" + answer + "\';"); boost::shared_ptr result = q.get_result(); cout << answer << " is "; if (!result->next_row()) @@ -180,6 +189,10 @@ int main(int argc, char *argv[]) } } break; + case 'h': + case 'H': + print_help(); + break; case 'q': case 'Q': keeprunning = false;