Rest of the operations boilerplate
This commit is contained in:
parent
287f9f4751
commit
b6967e665e
@ -4,4 +4,4 @@ project(budget)
|
|||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} src/main.cpp
|
add_executable(${PROJECT_NAME} src/main.cpp
|
||||||
src/optHandlers/mainOptHandler.h src/optHandlers/mainOptHandler.cpp src/optHandlers/operation.cpp src/optHandlers/operation.h src/optHandlers/accountOperation.cpp src/optHandlers/accountOperation.h)
|
src/optHandlers/mainOptHandler.h src/optHandlers/mainOptHandler.cpp src/optHandlers/operation.cpp src/optHandlers/operation.h src/optHandlers/accountOperation.cpp src/optHandlers/accountOperation.h src/optHandlers/createOperation.cpp src/optHandlers/createOperation.h src/optHandlers/earnOperation.cpp src/optHandlers/earnOperation.h src/optHandlers/PaymentOperation.cpp src/optHandlers/PaymentOperation.h)
|
||||||
|
13
src/optHandlers/PaymentOperation.cpp
Normal file
13
src/optHandlers/PaymentOperation.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "PaymentOperation.h"
|
||||||
|
|
||||||
|
using namespace Budget::OptHandlers;
|
||||||
|
|
||||||
|
void PaymentOperation::commit() {
|
||||||
|
//TODO This function will be called when the action needs to be done
|
||||||
|
}
|
||||||
|
|
||||||
|
PaymentOperation::PaymentOperation() = default;
|
34
src/optHandlers/PaymentOperation.h
Normal file
34
src/optHandlers/PaymentOperation.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef BUDGET_PAYMENTOPERATION_H
|
||||||
|
#define BUDGET_PAYMENTOPERATION_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <ctime>
|
||||||
|
#include "operation.h"
|
||||||
|
|
||||||
|
namespace Budget::OptHandlers {
|
||||||
|
class PaymentOperation : public Operation{
|
||||||
|
public:
|
||||||
|
void commit() override;
|
||||||
|
|
||||||
|
explicit PaymentOperation();
|
||||||
|
|
||||||
|
struct Flags : public Operation::Flags {
|
||||||
|
long double value;
|
||||||
|
std::string description;
|
||||||
|
std::string receipt;
|
||||||
|
long long date = std::time(nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Flags flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //BUDGET_PAYMENTOPERATION_H
|
@ -24,8 +24,7 @@ namespace Budget::OptHandlers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Flags flags;
|
Flags flags;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
} // OptHandlers
|
}
|
||||||
|
|
||||||
#endif //BUDGET_ACCOUNTOPERATION_H
|
#endif //BUDGET_ACCOUNTOPERATION_H
|
||||||
|
13
src/optHandlers/createOperation.cpp
Normal file
13
src/optHandlers/createOperation.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "createOperation.h"
|
||||||
|
|
||||||
|
using namespace Budget::OptHandlers;
|
||||||
|
|
||||||
|
void CreateOperation::commit() {
|
||||||
|
//TODO This function will be called when the action needs to be done
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateOperation::CreateOperation() = default;
|
27
src/optHandlers/createOperation.h
Normal file
27
src/optHandlers/createOperation.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef BUDGET_CREATEOPERATION_H
|
||||||
|
#define BUDGET_CREATEOPERATION_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "operation.h"
|
||||||
|
|
||||||
|
namespace Budget::OptHandlers {
|
||||||
|
class CreateOperation : public Operation{
|
||||||
|
public:
|
||||||
|
void commit() override;
|
||||||
|
|
||||||
|
explicit CreateOperation();
|
||||||
|
|
||||||
|
struct Flags : public Operation::Flags {
|
||||||
|
std::string description;
|
||||||
|
};
|
||||||
|
|
||||||
|
Flags flags;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //BUDGET_CREATEOPERATION_H
|
13
src/optHandlers/earnOperation.cpp
Normal file
13
src/optHandlers/earnOperation.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "earnOperation.h"
|
||||||
|
|
||||||
|
using namespace Budget::OptHandlers;
|
||||||
|
|
||||||
|
void EarnOperation::commit() {
|
||||||
|
//TODO This function will be called when the action needs to be done
|
||||||
|
}
|
||||||
|
|
||||||
|
EarnOperation::EarnOperation() = default;
|
32
src/optHandlers/earnOperation.h
Normal file
32
src/optHandlers/earnOperation.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef BUDGET_EARNOPERATION_H
|
||||||
|
#define BUDGET_EARNOPERATION_H
|
||||||
|
|
||||||
|
#include "operation.h"
|
||||||
|
#include <string>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
namespace Budget::OptHandlers {
|
||||||
|
class EarnOperation : public Operation{
|
||||||
|
public:
|
||||||
|
void commit() override;
|
||||||
|
|
||||||
|
explicit EarnOperation();
|
||||||
|
|
||||||
|
struct Flags : public Operation::Flags {
|
||||||
|
long double value;
|
||||||
|
std::string description;
|
||||||
|
std::string receipt;
|
||||||
|
long long date = std::time(nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Flags flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //BUDGET_EARNOPERATION_H
|
@ -3,8 +3,12 @@
|
|||||||
//
|
//
|
||||||
#include "mainOptHandler.h"
|
#include "mainOptHandler.h"
|
||||||
#include "accountOperation.h"
|
#include "accountOperation.h"
|
||||||
|
#include "createOperation.h"
|
||||||
|
#include "earnOperation.h"
|
||||||
|
#include "PaymentOperation.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
using namespace Budget::OptHandlers;
|
using namespace Budget::OptHandlers;
|
||||||
|
|
||||||
@ -113,6 +117,8 @@ void MainOptHandler::createOptHandler(std::string account) {
|
|||||||
{"description", required_argument, nullptr, 'd'},
|
{"description", required_argument, nullptr, 'd'},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto createOperation = std::make_unique<CreateOperation>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:d:", createLongOpts, nullptr);
|
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:d:", createLongOpts, nullptr);
|
||||||
if (opt == -1)
|
if (opt == -1)
|
||||||
@ -127,8 +133,10 @@ void MainOptHandler::createOptHandler(std::string account) {
|
|||||||
case 'e':
|
case 'e':
|
||||||
case 'p':
|
case 'p':
|
||||||
optind--;
|
optind--;
|
||||||
|
operations.push(std::move(createOperation));
|
||||||
return;
|
return;
|
||||||
case 'd':
|
case 'd':
|
||||||
|
createOperation->flags.description = optarg;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
help();
|
help();
|
||||||
@ -137,6 +145,7 @@ void MainOptHandler::createOptHandler(std::string account) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
operations.push(std::move(createOperation));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainOptHandler::earnOptHandler(std::string account) {
|
void MainOptHandler::earnOptHandler(std::string account) {
|
||||||
@ -151,11 +160,12 @@ void MainOptHandler::earnOptHandler(std::string account) {
|
|||||||
{"description", required_argument, nullptr, 'd'},
|
{"description", required_argument, nullptr, 'd'},
|
||||||
{"receipt", required_argument, nullptr, 'r'},
|
{"receipt", required_argument, nullptr, 'r'},
|
||||||
{"date", required_argument, nullptr, 'D'},
|
{"date", required_argument, nullptr, 'D'},
|
||||||
{"time", required_argument, nullptr, 't'}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto earnOperation = std::make_unique<EarnOperation>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:v:d:r:d:t:", earnLongOpts, nullptr);
|
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:v:d:r:D:", earnLongOpts, nullptr);
|
||||||
if (opt == -1)
|
if (opt == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -168,17 +178,37 @@ void MainOptHandler::earnOptHandler(std::string account) {
|
|||||||
case 'e':
|
case 'e':
|
||||||
case 'p':
|
case 'p':
|
||||||
optind--;
|
optind--;
|
||||||
|
operations.push(std::move(earnOperation));
|
||||||
return;
|
return;
|
||||||
case 'v':
|
case 'v': {
|
||||||
|
try {
|
||||||
|
earnOperation->flags.value = std::stod(optarg);
|
||||||
|
} catch (std::exception const &e) {
|
||||||
|
help();
|
||||||
|
std::cout << "Bad value value" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'd':
|
case 'd':
|
||||||
|
earnOperation->flags.description = optarg;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
earnOperation->flags.receipt = optarg;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D': {
|
||||||
break;
|
struct tm t{};
|
||||||
case 't':
|
time_t ts;
|
||||||
|
memset(&t, 0, sizeof(struct tm));
|
||||||
|
if (strptime(optarg, "%m/%d/%YT%H:%M:%S", &t) == nullptr) {
|
||||||
|
help();
|
||||||
|
std::cout << "Bad time value" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
ts = mktime(&t);
|
||||||
|
earnOperation->flags.date = (long long) ts;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case '?':
|
case '?':
|
||||||
help();
|
help();
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -186,6 +216,7 @@ void MainOptHandler::earnOptHandler(std::string account) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
operations.push(std::move(earnOperation));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainOptHandler::paymentOptHandler(std::string account) {
|
void MainOptHandler::paymentOptHandler(std::string account) {
|
||||||
@ -200,11 +231,12 @@ void MainOptHandler::paymentOptHandler(std::string account) {
|
|||||||
{"description", required_argument, nullptr, 'd'},
|
{"description", required_argument, nullptr, 'd'},
|
||||||
{"receipt", required_argument, nullptr, 'r'},
|
{"receipt", required_argument, nullptr, 'r'},
|
||||||
{"date", required_argument, nullptr, 'D'},
|
{"date", required_argument, nullptr, 'D'},
|
||||||
{"time", required_argument, nullptr, 't'}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto payOperation = std::make_unique<PaymentOperation>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:v:d:r:D:t", paymentLongOpts, nullptr);
|
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:v:d:r:D", paymentLongOpts, nullptr);
|
||||||
if (opt == -1)
|
if (opt == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -217,17 +249,37 @@ void MainOptHandler::paymentOptHandler(std::string account) {
|
|||||||
case 'e':
|
case 'e':
|
||||||
case 'p':
|
case 'p':
|
||||||
optind--;
|
optind--;
|
||||||
|
operations.push(std::move(payOperation));
|
||||||
return;
|
return;
|
||||||
case 'v':
|
case 'v': {
|
||||||
|
try {
|
||||||
|
payOperation->flags.value = std::stod(optarg);
|
||||||
|
} catch (std::exception const &e) {
|
||||||
|
help();
|
||||||
|
std::cout << "Bad value value" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'd':
|
case 'd':
|
||||||
|
payOperation->flags.description = optarg;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
payOperation->flags.receipt = optarg;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D': {
|
||||||
break;
|
struct tm t{};
|
||||||
case 't':
|
time_t ts;
|
||||||
|
memset(&t, 0, sizeof(struct tm));
|
||||||
|
if (strptime(optarg, "%m/%d/%YT%H:%M:%S", &t) == nullptr) {
|
||||||
|
help();
|
||||||
|
std::cout << "Bad time value" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
ts = mktime(&t);
|
||||||
|
payOperation->flags.date = (long long) ts;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case '?':
|
case '?':
|
||||||
help();
|
help();
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -235,6 +287,7 @@ void MainOptHandler::paymentOptHandler(std::string account) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
operations.push(std::move(payOperation));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainOptHandler::help() {
|
void MainOptHandler::help() {
|
||||||
@ -258,14 +311,12 @@ void MainOptHandler::help() {
|
|||||||
std::cout << "\t-v --value=<FlOAT> Value for earning." << 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-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-r --receipt=<PATH> Path to file to store in DB as receipt." << std::endl;
|
||||||
std::cout << "\t-D --date=<dd/mm/yyyy> Date as dd/mm/yyyy. Default will be today." << 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 << "\t-t --time=<hh/mm/ss> 24 hour time as hh/mm/ss. Default will be now." << std::endl;
|
|
||||||
std::cout << "Payment Options: -v [-drD]" << std::endl;
|
std::cout << "Payment Options: -v [-drD]" << std::endl;
|
||||||
std::cout << "\t-v --value=<FlOAT> Value for payment." << 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-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-r --receipt=<PATH> Path to file to store in DB as receipt." << std::endl;
|
||||||
std::cout << "\t-D --date=<NUM/NUM/NUM> Date as dd/mm/yyyy. Default will be today." << 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 << "\t-t --time=<hh/mm/ss> 24 hour time as hh/mm/ss. Default will be now." << std::endl;
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "Arguments are processed like blocks with each one terminated by the next Action. For example"
|
std::cout << "Arguments are processed like blocks with each one terminated by the next Action. For example"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user