From: José Iván López González Date: Wed, 30 Oct 2019 23:12:29 +0000 (+0000) Subject: Add Command base class X-Git-Tag: v0.8.6~10^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bcbd95f27f5a3dff755c4c77162d5576a2fa15a8;p=thirdparty%2Fsnapper.git Add Command base class --- diff --git a/client/Command.cc b/client/Command.cc new file mode 100644 index 00000000..16afbb30 --- /dev/null +++ b/client/Command.cc @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2019] SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + +#include "client/Command.h" + +using namespace std; + +namespace snapper +{ + namespace cli + { + + Command::Command(const GlobalOptions& global_options, GetOpts& options_parser, + ProxySnappers& snappers) : + _options_parser(options_parser), _global_options(global_options), _snappers(snappers) + {} + + + bool Command::has_errors() const + { + return !errors().empty(); + } + + + Command::~Command() + {} + + } +} diff --git a/client/Command.h b/client/Command.h new file mode 100644 index 00000000..9ce77600 --- /dev/null +++ b/client/Command.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2019] SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + +#ifndef SNAPPER_CLI_COMMAND_H +#define SNAPPER_CLI_COMMAND_H + +#include +#include + +#include "client/GlobalOptions.h" +#include "client/proxy.h" +#include "client/utils/GetOpts.h" +#include "client/utils/Table.h" + +namespace snapper +{ + namespace cli + { + + class Command + { + + public: + + class ColumnsOption; + + class GetConfig; + + class ListConfigs; + + class ListSnapshots; + + Command(const GlobalOptions& global_options, GetOpts& options_parser, + ProxySnappers& snappers); + + const GlobalOptions& global_options() const + { + return _global_options; + } + + ProxySnappers& snappers() const + { + return _snappers; + } + + virtual bool has_errors() const; + + virtual std::vector errors() const = 0; + + virtual void run() = 0; + + virtual ~Command(); + + protected: + + GetOpts& _options_parser; + + private: + + const GlobalOptions& _global_options; + + ProxySnappers& _snappers; + + }; + + } +} + +#endif diff --git a/client/GlobalOptions.cc b/client/GlobalOptions.cc new file mode 100644 index 00000000..7a168ac3 --- /dev/null +++ b/client/GlobalOptions.cc @@ -0,0 +1,248 @@ +/* + * Copyright (c) [2019] SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + +#include + +#include "client/GlobalOptions.h" +#include "client/utils/text.h" +#include "client/utils/TableFormatter.h" +#include "client/utils/CsvFormatter.h" + +using namespace std; + +namespace snapper +{ + namespace cli + { + + namespace + { + + const string CSV_OPTION = "csv"; + + const string JSON_OPTION = "json"; + + const string DEFAULT_CONFIG = "root"; + + const string DEFAULT_ROOT = "/"; + + const option OPTIONS[15] = { + { "quiet", no_argument, 0, 'q' }, + { "verbose", no_argument, 0, 'v' }, + { "utc", no_argument, 0, 0 }, + { "iso", no_argument, 0, 0 }, + { "table-style", required_argument, 0, 't' }, + { "machine-readable", required_argument, 0, 0}, + { "csvout", no_argument, 0, 0}, + { "jsonout", no_argument, 0, 0}, + { "separator", required_argument, 0, 0}, + { "config", required_argument, 0, 'c' }, + { "no-dbus", no_argument, 0, 0 }, + { "root", required_argument, 0, 'r' }, + { "version", no_argument, 0, 0 }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + } + + + string GlobalOptions::help_text() + { + return string(_(" Global options:")) + '\n' + + _("\t--quiet, -q\t\t\tSuppress normal output.") + '\n' + + _("\t--verbose, -v\t\t\tIncrease verbosity.") + '\n' + + _("\t--utc\t\t\t\tDisplay dates and times in UTC.") + '\n' + + _("\t--iso\t\t\t\tDisplay dates and times in ISO format.") + '\n' + + _("\t--table-style, -t