budget/src/optHandlers/accountOptHandler.cpp

73 lines
1.7 KiB
C++

//
// Created by quentin on 8/13/22.
//
#include <iostream>
#include "accountOptHandler.h"
using namespace Budget::OptHandlers;
void AccountOptHandler::parse() {
std::string test;
struct option longOpts[] = {
{"help", no_argument, nullptr, 'h'},
{"list", no_argument, nullptr, 'l'},
{"delete", required_argument, nullptr, 'd'},
{"create", required_argument, nullptr, 'c'},
{"value", required_argument, nullptr, 'v'},
{nullptr}
};
while (true) {
int opt = getopt_long(getArgc(), getArgv(), "hl::d::c::v", longOpts, nullptr);
if (opt == -1) {
break;
}
switch (opt) {
case 'h':
setOpts.help = true;
break;
case 'l':
setOpts.list = true;
break;
case 'd':
setOpts.del = true;
setOpts.delAccount = optarg;
break;
case 'c':
setOpts.create = true;
setOpts.createAccount = optarg;
break;
case 'v':
setOpts.value = true;
setOpts.valueAccount = optarg;
break;
case '?':
setOpts.help = true;
setOpts.helpOut = stderr;
break;
default:
break;
}
}
}
void AccountOptHandler::help() {
fprintf(setOpts.helpOut, "Help budget -a {-cvd account|-hl}\n");
fprintf(setOpts.helpOut, " -h --help Output this message.\n");
fprintf(setOpts.helpOut, " -l --list List available accounts.\n");
fprintf(setOpts.helpOut, " -d --delete account Delete the specified account.\n");
fprintf(setOpts.helpOut, " -c --create account Create a new account.\n");
fprintf(setOpts.helpOut, " -v --value account Print the current value of account.\n");
}
const SetOpts *AccountOptHandler::getSetOpts() const {
return &setOpts;
}
AccountOptHandler::AccountOptHandler(const std::vector<char *> &argv) : OptHandler(argv) {}