added feature to print help

develop
tastytea 2018-08-30 16:54:34 +02:00
parent 26a09fe58f
commit 133f7f9c2a
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
3 changed files with 28 additions and 8 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (whyblocked
VERSION 0.4.0
VERSION 0.5.0
LANGUAGES CXX
)

View File

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

View File

@ -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<sqlite::result> 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;