added feature to print help
parent
26a09fe58f
commit
133f7f9c2a
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (whyblocked
|
project (whyblocked
|
||||||
VERSION 0.4.0
|
VERSION 0.5.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,17 @@ It has a text interface and uses a SQLite-database.
|
||||||
|
|
||||||
```PLAIN
|
```PLAIN
|
||||||
$ whyblocked
|
$ 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 add, remove, view or details. Or just the first letter.
|
||||||
Type quit or q to quit the program.
|
Type quit or q to quit the program.
|
||||||
: add
|
: add
|
||||||
User or instance: @tastytea@soc.ialis.me
|
User or instance: @tastytea@soc.ialis.me
|
||||||
Blocked(b) or silenced(s): b
|
Blocked(b) or silenced(s): b
|
||||||
Reason: Too nice
|
Reason: Too nice
|
||||||
|
@tastytea@soc.ialis.me added.
|
||||||
Add receipt? [y/n] y
|
Add receipt? [y/n] y
|
||||||
URL: https://tastytea.de/
|
URL: https://tastytea.de/
|
||||||
|
Receipt added.
|
||||||
Add receipt? [y/n] n
|
Add receipt? [y/n] n
|
||||||
: view
|
: view
|
||||||
Blocked: @tastytea@soc.ialis.me because: Too nice
|
Blocked: @tastytea@soc.ialis.me because: Too nice
|
||||||
|
@ -28,6 +30,11 @@ Receipts:
|
||||||
https://tastytea.de/
|
https://tastytea.de/
|
||||||
: remove
|
: remove
|
||||||
User or instance: @tastytea@soc.ialis.me
|
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
|
: quit
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ string get_filepath()
|
||||||
filepath = xdgDataHome(&xdg);
|
filepath = xdgDataHome(&xdg);
|
||||||
xdgWipeHandle(&xdg);
|
xdgWipeHandle(&xdg);
|
||||||
|
|
||||||
filepath += "/whyblock";
|
filepath += "/whyblocked";
|
||||||
if (!fs::exists(filepath))
|
if (!fs::exists(filepath))
|
||||||
{
|
{
|
||||||
fs::create_directory(filepath);
|
fs::create_directory(filepath);
|
||||||
|
@ -33,13 +33,20 @@ string get_filepath()
|
||||||
if (!fs::exists(filepath))
|
if (!fs::exists(filepath))
|
||||||
{
|
{
|
||||||
sqlite::connection con(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);
|
sqlite::execute(con, "CREATE TABLE urls(user TEXT, url TEXT);", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath;
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -48,8 +55,7 @@ int main(int argc, char *argv[])
|
||||||
bool keeprunning = true;
|
bool keeprunning = true;
|
||||||
|
|
||||||
cout << "This is whyblocked " << global::version << ".\n";
|
cout << "This is whyblocked " << global::version << ".\n";
|
||||||
cout << "Type add, remove, view or details. Or just the first letter.\n";
|
print_help();
|
||||||
cout << "Type quit or q to quit the program.\n";
|
|
||||||
while (keeprunning)
|
while (keeprunning)
|
||||||
{
|
{
|
||||||
string answer = "";
|
string answer = "";
|
||||||
|
@ -84,6 +90,7 @@ int main(int argc, char *argv[])
|
||||||
sqlite::execute ins(con, "INSERT INTO blocks VALUES(?, ?, ?);");
|
sqlite::execute ins(con, "INSERT INTO blocks VALUES(?, ?, ?);");
|
||||||
ins % user % blocked % reason;
|
ins % user % blocked % reason;
|
||||||
ins();
|
ins();
|
||||||
|
cout << user << " added.\n";
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -98,6 +105,7 @@ int main(int argc, char *argv[])
|
||||||
sqlite::execute ins(con, "INSERT INTO urls VALUES(?, ?);");
|
sqlite::execute ins(con, "INSERT INTO urls VALUES(?, ?);");
|
||||||
ins % user % url;
|
ins % user % url;
|
||||||
ins();
|
ins();
|
||||||
|
cout << "Receipt added.\n";
|
||||||
}
|
}
|
||||||
else if (answer[0] == 'n' || answer[0] == 'N')
|
else if (answer[0] == 'n' || answer[0] == 'N')
|
||||||
{
|
{
|
||||||
|
@ -123,7 +131,7 @@ int main(int argc, char *argv[])
|
||||||
rm_urls % user;
|
rm_urls % user;
|
||||||
rm_blocks();
|
rm_blocks();
|
||||||
rm_urls();
|
rm_urls();
|
||||||
|
cout << user << " removed.\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'v':
|
case 'v':
|
||||||
|
@ -152,7 +160,8 @@ int main(int argc, char *argv[])
|
||||||
cout << "User or instance: ";
|
cout << "User or instance: ";
|
||||||
cin >> answer;
|
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();
|
boost::shared_ptr<sqlite::result> result = q.get_result();
|
||||||
cout << answer << " is ";
|
cout << answer << " is ";
|
||||||
if (!result->next_row())
|
if (!result->next_row())
|
||||||
|
@ -180,6 +189,10 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
case 'H':
|
||||||
|
print_help();
|
||||||
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
case 'Q':
|
case 'Q':
|
||||||
keeprunning = false;
|
keeprunning = false;
|
||||||
|
|
Loading…
Reference in New Issue