Code cleanup
This commit is contained in:
parent
5a88299f9e
commit
2c3436ee94
@ -39,7 +39,7 @@ void Database::deleteAccount(const std::string &account, sqlite3 *db) {
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
|
||||
if (rc != SQLITE_DONE)
|
||||
throw std::runtime_error("Failed to delete account " + account);
|
||||
}
|
||||
@ -108,7 +108,7 @@ double Database::cacheAccountValue(long long accountId, sqlite3 *db) {
|
||||
throw std::runtime_error("Failed to set cashedValue for " + std::to_string(accountId));
|
||||
}
|
||||
|
||||
void Database::accountDescription(const std::string& account, const std::string& description, sqlite3 *db) {
|
||||
void Database::accountDescription(const std::string &account, const std::string &description, sqlite3 *db) {
|
||||
sqlite3_stmt *stmt;
|
||||
int rc = sqlite3_prepare_v2(db, "UPDATE account SET description = ? WHERE name = ?", -1, &stmt, nullptr);
|
||||
|
||||
|
@ -64,7 +64,7 @@ void MainOptHandler::accountOptHandler(std::string account) {
|
||||
{"delete", no_argument, nullptr, 'd'},
|
||||
{"force-delete", no_argument, nullptr, 'F'},
|
||||
{"value", no_argument, nullptr, 'v'},
|
||||
{"description", required_argument, nullptr, 'D'},
|
||||
{"description", required_argument, nullptr, 'D'},
|
||||
};
|
||||
|
||||
auto acctOperation = std::make_unique<AccountOperation>(db, account);
|
||||
@ -293,40 +293,39 @@ void MainOptHandler::paymentOptHandler(std::string account) {
|
||||
}
|
||||
|
||||
void MainOptHandler::help() {
|
||||
std::cout << "Output of budget." << std::endl;
|
||||
std::cout << "Usage:" << std::endl;
|
||||
std::cout << "\tbudget <action> [options] ..." << std::endl;
|
||||
std::cout << "Actions:" << std::endl;
|
||||
std::cout << "\t-h --help Prints this." << std::endl;
|
||||
std::cout << "\t-a --account<=STRING> Management tools for an account." << std::endl;
|
||||
std::cout << "\t-c --create<=STRING> Creates a new account with NAME." << std::endl;
|
||||
std::cout << "\t-e --earn<=STRING> Add an earning to an account." << std::endl;
|
||||
std::cout << "\t-p --payment<=STRING> Add a payment to an account." << std::endl;
|
||||
std::cout << "Account Options: [-dvD]" << std::endl;
|
||||
std::cout << "\t-d --delete Deletes specified account." << std::endl;
|
||||
std::cout << "\t--force-delete Deletes the specified account without confirmation." << std::endl;
|
||||
std::cout << "\t-v --value Gets the current value of the account." << std::endl;
|
||||
std::cout << "\t-D --description<=STRING> Changes the description of the account." << std::endl;
|
||||
std::cout << "Create Options: [-d]" << std::endl;
|
||||
std::cout << "\t-d --description<=STRING> Sets a description for an account." << std::endl;
|
||||
std::cout << "Earn Options: -v [-drD]" << std::endl;
|
||||
std::cout << "\t-v --value=<FlOAT> Value for earning." << std::endl;
|
||||
std::cout << "\t-d --description=<STRING> Description for earning." << std::endl;
|
||||
std::cout << "\t-r --receipt=<PATH> Path to file to store in DB as receipt." << std::endl;
|
||||
std::cout << "\t-D --date=<mm/dd/yyyyTHH:MM:SS> Date as dd/mm/yyyyTHH:MM:SS. Default will be today." << std::endl;
|
||||
std::cout << "Payment Options: -v [-drD]" << std::endl;
|
||||
std::cout << "\t-v --value=<FlOAT> Value for payment." << std::endl;
|
||||
std::cout << "\t-d --description=<STRING> Description for payment." << std::endl;
|
||||
std::cout << "\t-r --receipt=<PATH> Path to file to store in DB as receipt." << std::endl;
|
||||
std::cout << "\t-D --date=<mm/dd/yyyyTHH:MM:SS> Date as dd/mm/yyyyTHH:MM:SS. Default will be today." << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Arguments are processed like blocks with each one terminated by the next Action. For example"
|
||||
<< std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << R"(budget -cAcct -eAcct -v10.00 -r"./receipt.pdf" -pAcct -v5.50 -r"./payment.pdf")" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Does the following in order:" << std::endl;
|
||||
std::cout << "Creates an account named Acct with no description." << std::endl;
|
||||
std::cout << "Earns 10.00 to it with a receipt." << std::endl;
|
||||
std::cout << "Pays 5.50 to it with a receipt." << std::endl;
|
||||
std::cout << "Output of budget.\n"
|
||||
"Usage:\n"
|
||||
" budget <action> [options] ...\n"
|
||||
"Actions:\n"
|
||||
" -h --help Prints this.\n"
|
||||
" -a --account<=STRING> Management tools for an account.\n"
|
||||
" -c --create<=STRING> Creates a new account with NAME.\n"
|
||||
" -e --earn<=STRING> Add an earning to an account.\n"
|
||||
" -p --payment<=STRING> Add a payment to an account.\n"
|
||||
"Account Options: [-dvD]\n"
|
||||
" -d --delete Deletes specified account.\n"
|
||||
" --force-delete Deletes the specified account without confirmation.\n"
|
||||
" -v --value Gets the current value of the account.\n"
|
||||
" -D --description<=STRING> Changes the description of the account.\n"
|
||||
"Create Options: [-d]\n"
|
||||
" -d --description<=STRING> Sets a description for an account.\n"
|
||||
"Earn Options: -v [-drD]\n"
|
||||
" -v --value=<FlOAT> Value for earning.\n"
|
||||
" -d --description=<STRING> Description for earning.\n"
|
||||
" -r --receipt=<PATH> Path to file to store in DB as receipt.\n"
|
||||
" -D --date=<mm/dd/yyyyTHH:MM:SS> Date as dd/mm/yyyyTHH:MM:SS. Default will be today.\n"
|
||||
"Payment Options: -v [-drD]\n"
|
||||
" -v --value=<FlOAT> Value for payment.\n"
|
||||
" -d --description=<STRING> Description for payment.\n"
|
||||
" -r --receipt=<PATH> Path to file to store in DB as receipt.\n"
|
||||
" -D --date=<mm/dd/yyyyTHH:MM:SS> Date as dd/mm/yyyyTHH:MM:SS. Default will be today.\n"
|
||||
"\n"
|
||||
"Arguments are processed like blocks with each one terminated by the next Action. For example\n"
|
||||
"\n"
|
||||
"budget -cAcct -eAcct -v10.00 -r\"./receipt.pdf\" -pAcct -v5.50 -r\"./payment.pdf\"\n"
|
||||
"\n"
|
||||
"Does the following in order:\n"
|
||||
"Creates an account named Acct with no description.\n"
|
||||
"Earns 10.00 to it with a receipt.\n"
|
||||
"Pays 5.50 to it with a receipt." << std::endl;
|
||||
}
|
||||
|
@ -9,16 +9,18 @@
|
||||
|
||||
class SqliteDb {
|
||||
public:
|
||||
explicit SqliteDb(sqlite3* db) : m_db(db) {}
|
||||
explicit SqliteDb(sqlite3 *db) : m_db(db) {}
|
||||
|
||||
~SqliteDb() {
|
||||
sqlite3_close(m_db);
|
||||
}
|
||||
explicit operator sqlite3*() {
|
||||
|
||||
explicit operator sqlite3 *() {
|
||||
return m_db;
|
||||
}
|
||||
|
||||
private:
|
||||
sqlite3* m_db;
|
||||
sqlite3 *m_db;
|
||||
};
|
||||
|
||||
#endif //BUDGET_SQLITEDB_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user