Operations and AccountOperations boilerplate
This commit is contained in:
parent
94e63e8f76
commit
287f9f4751
@ -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/mainOptHandler.h src/optHandlers/mainOptHandler.cpp src/optHandlers/operation.cpp src/optHandlers/operation.h src/optHandlers/accountOperation.cpp src/optHandlers/accountOperation.h)
|
||||||
|
15
src/optHandlers/accountOperation.cpp
Normal file
15
src/optHandlers/accountOperation.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "accountOperation.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
using namespace Budget::OptHandlers;
|
||||||
|
|
||||||
|
void AccountOperation::commit() {
|
||||||
|
//TODO This function will be called when the action needs to be done
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountOperation::AccountOperation() = default;
|
31
src/optHandlers/accountOperation.h
Normal file
31
src/optHandlers/accountOperation.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef BUDGET_ACCOUNTOPERATION_H
|
||||||
|
#define BUDGET_ACCOUNTOPERATION_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include "operation.h"
|
||||||
|
|
||||||
|
namespace Budget::OptHandlers {
|
||||||
|
class AccountOperation : public Operation {
|
||||||
|
public:
|
||||||
|
void commit() override;
|
||||||
|
|
||||||
|
explicit AccountOperation();
|
||||||
|
|
||||||
|
struct Flags : public Operation::Flags {
|
||||||
|
bool del = false;
|
||||||
|
bool forceDel = false;
|
||||||
|
bool value = false;
|
||||||
|
std::string description;
|
||||||
|
};
|
||||||
|
|
||||||
|
Flags flags;
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
} // OptHandlers
|
||||||
|
|
||||||
|
#endif //BUDGET_ACCOUNTOPERATION_H
|
@ -2,6 +2,7 @@
|
|||||||
// Created by quentin on 1/8/23.
|
// Created by quentin on 1/8/23.
|
||||||
//
|
//
|
||||||
#include "mainOptHandler.h"
|
#include "mainOptHandler.h"
|
||||||
|
#include "accountOperation.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
@ -60,6 +61,8 @@ void MainOptHandler::accountOptHandler(std::string account) {
|
|||||||
{"description", no_argument, nullptr, 'D'},
|
{"description", no_argument, nullptr, 'D'},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto acctOperation = std::make_unique<AccountOperation>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:dFvD", accountLongOpts, nullptr);
|
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:dFvD", accountLongOpts, nullptr);
|
||||||
if (opt == -1)
|
if (opt == -1)
|
||||||
@ -74,14 +77,20 @@ void MainOptHandler::accountOptHandler(std::string account) {
|
|||||||
case 'e':
|
case 'e':
|
||||||
case 'p':
|
case 'p':
|
||||||
optind--;
|
optind--;
|
||||||
|
operations.push(std::move(acctOperation));
|
||||||
return;
|
return;
|
||||||
case 'd':
|
case 'd':
|
||||||
|
acctOperation->flags.del = true;
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
|
acctOperation->flags.del = true;
|
||||||
|
acctOperation->flags.forceDel = true;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
|
acctOperation->flags.value = true;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
|
acctOperation->flags.description = optarg;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
help();
|
help();
|
||||||
@ -90,6 +99,7 @@ void MainOptHandler::accountOptHandler(std::string account) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
operations.push(std::move(acctOperation));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainOptHandler::createOptHandler(std::string account) {
|
void MainOptHandler::createOptHandler(std::string account) {
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <queue>
|
||||||
|
#include <memory>
|
||||||
|
#include "operation.h"
|
||||||
|
|
||||||
namespace Budget::OptHandlers{
|
namespace Budget::OptHandlers{
|
||||||
class MainOptHandler {
|
class MainOptHandler {
|
||||||
@ -15,6 +18,8 @@ namespace Budget::OptHandlers{
|
|||||||
|
|
||||||
void help();
|
void help();
|
||||||
|
|
||||||
|
std::queue<std::unique_ptr<Operation>> operations;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void accountOptHandler(std::string account);
|
void accountOptHandler(std::string account);
|
||||||
|
|
||||||
|
5
src/optHandlers/operation.cpp
Normal file
5
src/optHandlers/operation.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "operation.h"
|
18
src/optHandlers/operation.h
Normal file
18
src/optHandlers/operation.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Created by quentin on 1/17/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef BUDGET_OPERATION_H
|
||||||
|
#define BUDGET_OPERATION_H
|
||||||
|
|
||||||
|
namespace Budget::OptHandlers {
|
||||||
|
class Operation {
|
||||||
|
public:
|
||||||
|
virtual void commit() = 0;
|
||||||
|
struct Flags {
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //BUDGET_OPERATION_H
|
Loading…
x
Reference in New Issue
Block a user