Config file and package tracking utility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

96 lines
2.1 KiB

/*
* Copyright (C) 2021-2022 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#include <cstdio> // fprintf, stderr
#include <string>
#include <vector>
#include "config.h"
#include "dotfile.h"
#include "package.h"
#include "util/argparser.h"
#include "util/timer.h"
int main(int argc, const char* argv[])
{
bool fileOperation = false;
bool packageOperation = false;
bool helpOperation = false;
bool addOrAur = false;
bool install = false;
bool pull = false;
bool pushOrStore = false;
bool verbose = false;
std::vector<std::string> targets {};
Util::ArgParser argParser;
argParser.addOption(fileOperation, 'F', "file", nullptr, nullptr);
argParser.addOption(packageOperation, 'P', "package", nullptr, nullptr);
argParser.addOption(helpOperation, 'h', "help", nullptr, nullptr);
argParser.addOption(addOrAur, 'a', "add", nullptr, nullptr);
argParser.addOption(install, 'i', "install", nullptr, nullptr);
argParser.addOption(pull, 'l', "pull", nullptr, nullptr);
argParser.addOption(pushOrStore, 's', "push", nullptr, nullptr);
argParser.addOption(verbose, 'v', "verbose", nullptr, nullptr);
argParser.addArgument(targets, "targets", nullptr, nullptr, Util::ArgParser::Required::No);
argParser.parse(argc, argv);
if (fileOperation + packageOperation + helpOperation > 1) {
fprintf(stderr, "\033[31;1mError:\033[0m only one operation may be used at a time\n");
return 1;
}
#ifndef NDEBUG
Util::Timer t;
#endif
Config::the().setVerbose(verbose);
if (fileOperation) {
if (addOrAur) {
Dotfile::the().add(targets);
}
if (pull) {
Dotfile::the().pull(targets);
}
if (pushOrStore) {
Dotfile::the().push(targets);
}
if (!addOrAur && !pull && !pushOrStore) {
Dotfile::the().list(targets);
}
}
else if (packageOperation) {
if (addOrAur) {
Package::the().aurInstall();
}
if (install) {
Package::the().install();
}
if (pushOrStore) {
Package::the().store();
}
if (!addOrAur && !install && !pushOrStore) {
Package::the().list(targets);
}
}
else if (helpOperation) {
// TODO open manpage
}
else {
// TODO open manpage
}
#ifndef NDEBUG
printf("%fms\n", t.elapsedNanoseconds() / 1000000.0);
#endif
return 0;
}