#include "macros.hpp"
#include "common.hpp"
#include <cstdio>
#include <getopt.h>
#include <sys/stat.h>
static const struct option longopts[] =
{
{ "help", no_argument, NULL, 'h' },
{ "verbose", no_argument, NULL, 'v' },
{ "linger", no_argument, NULL, 'l' },
{ "force-sync", no_argument, NULL, 'y' },
{ "suspend-services", no_argument, NULL, 's' },
{ "restart-services", no_argument, NULL, 'r' },
{ "changes-pending", no_argument, NULL, 'c' },
{ "list-pending", no_argument, NULL, 'p' },
{ "list-defaults", no_argument, NULL, 'd' },
{ NULL, 0, NULL, 0 }
};
bool Options::Verbose = false;
bool Options::Debug = false;
bool Options::Linger = false;
bool Options::ForceSync = false;
bool Options::ForceSuspend = false;
bool Options::ForceRestart = false;
Options::command_type Options::Command = Options::SYNC;
static void print_help(void)
{
static const char help[] =
"Usage: synchronize-preferences [options]\n"
" --verbose print extra debugging messages\n"
" --linger check in with launchd and around and\n"
" sync updates until idle\n"
" --force-sync force synchronization even if it is\n"
" unnecessary\n"
" --restart-services restart any services that are\n"
" already running\n"
" --suspend-services leave all services disabled\n"
" --changes-pending exit with 0 status if there are\n"
" unsynchronized changes\n"
" --list-pending print the pending configuration, but\n"
" do not synchronize\n"
" --list-defaults print the default configuration and exit\n"
;
std::fprintf(stdout, "%s", help);
}
void Options::parse(int argc, char * const * argv)
{
int c;
while ((c = ::getopt_long(argc, argv, "", longopts, NULL)) != -1) {
switch (c) {
case '?': exit(1); break;
case 'h': print_help(); exit(0); break;
case 'v': Options::Verbose = true; break;
case 'l': Options::Linger = true; break;
case 'y': Options::ForceSync = true; break;
case 's': Options::ForceSuspend = true; break;
case 'r': Options::ForceRestart = true; break;
case 'c': Options::Command = Options::CHANGES_PENDING; break;
case 'p': Options::Command = Options::LIST_PENDING; break;
case 'd': Options::Command = Options::LIST_DEFAULTS; break;
}
}
}