]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Add ListConfigs command
authorJosé Iván López González <jlopez@suse.com>
Wed, 30 Oct 2019 23:18:19 +0000 (23:18 +0000)
committerJosé Iván López González <jlopez@suse.com>
Wed, 30 Oct 2019 23:18:19 +0000 (23:18 +0000)
14 files changed:
client/Command/ListConfigs.cc [new file with mode: 0644]
client/Command/ListConfigs.h [new file with mode: 0644]
client/Command/ListConfigs/Makefile.am [new file with mode: 0644]
client/Command/ListConfigs/Options.cc [new file with mode: 0644]
client/Command/ListConfigs/Options.h [new file with mode: 0644]
client/Command/ListConfigs/SnappersData.cc [new file with mode: 0644]
client/Command/ListConfigs/SnappersData.h [new file with mode: 0644]
client/Command/ListConfigs/SnappersData/Csv.cc [new file with mode: 0644]
client/Command/ListConfigs/SnappersData/Csv.h [new file with mode: 0644]
client/Command/ListConfigs/SnappersData/Json.cc [new file with mode: 0644]
client/Command/ListConfigs/SnappersData/Json.h [new file with mode: 0644]
client/Command/ListConfigs/SnappersData/Makefile.am [new file with mode: 0644]
client/Command/ListConfigs/SnappersData/Table.cc [new file with mode: 0644]
client/Command/ListConfigs/SnappersData/Table.h [new file with mode: 0644]

diff --git a/client/Command/ListConfigs.cc b/client/Command/ListConfigs.cc
new file mode 100644 (file)
index 0000000..5f070e5
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * 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 <iostream>
+
+#include "client/utils/text.h"
+#include "client/Command/ListConfigs.h"
+#include "client/Command/ListConfigs/Options.h"
+#include "client/Command/ListConfigs/SnappersData/Table.h"
+#include "client/Command/ListConfigs/SnappersData/Csv.h"
+#include "client/Command/ListConfigs/SnappersData/Json.h"
+
+using namespace std;
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       string Command::ListConfigs::help()
+       {
+           return
+               string(
+                   _("  List configs:\n"
+                     "\tsnapper list-configs\n"
+                     "\n")
+               ) + Options::help_text();
+       }
+
+
+       Command::ListConfigs::ListConfigs(const GlobalOptions& global_options,
+           GetOpts& options_parser, ProxySnappers& snappers) :
+           Command(global_options, options_parser, snappers), _options(new Options(options_parser))
+       {}
+
+
+       Command::ListConfigs::ListConfigs::~ListConfigs()
+       {}
+
+
+       const Command::ListConfigs::Options& Command::ListConfigs::options() const
+       {
+           return *_options.get();
+       }
+
+
+       vector<string> Command::ListConfigs::errors() const
+       {
+           return options().errors();
+       }
+
+
+       void Command::ListConfigs::run()
+       {
+           if (_options_parser.hasArgs())
+           {
+               cerr << _("Command 'list-configs' does not take arguments.") << endl;
+               exit(EXIT_FAILURE);
+           }
+
+           if (options().has_errors())
+           {
+               cerr << options().errors().front() << endl;
+               exit(EXIT_FAILURE);
+           }
+
+           string output;
+
+           switch (global_options().output_format())
+           {
+               case GlobalOptions::OutputFormat::TABLE:
+               {
+                   SnappersData::Table table(*this, global_options().table_style());
+                   output = table.output();
+               }
+               break;
+
+               case GlobalOptions::OutputFormat::CSV:
+               {
+                   SnappersData::Csv csv(*this, global_options().separator());
+                   output = csv.output();
+               }
+               break;
+
+               case GlobalOptions::OutputFormat::JSON:
+               {
+                   SnappersData::Json json(*this);
+                   output = json.output() + "\n";
+               }
+               break;
+           }
+
+           cout << output;
+       }
+
+    }
+}
diff --git a/client/Command/ListConfigs.h b/client/Command/ListConfigs.h
new file mode 100644 (file)
index 0000000..25e805e
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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_LIST_CONFIGS_H
+#define SNAPPER_CLI_COMMAND_LIST_CONFIGS_H
+
+#include <memory>
+
+#include "client/Command.h"
+#include "client/proxy.h"
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       class Command::ListConfigs : public Command
+       {
+
+       public:
+
+           class Options;
+
+           class ColumnsOption;
+
+           class SnappersData;
+
+           static std::string help();
+
+           ListConfigs(const GlobalOptions& global_options, GetOpts& options_parser,
+               ProxySnappers& snappers);
+
+           const Options& options() const;
+
+           virtual std::vector<std::string> errors() const override;
+
+           virtual void run() override;
+
+           virtual ~ListConfigs();
+
+       private:
+
+           std::unique_ptr<Options> _options;
+       };
+
+    }
+}
+
+#endif
diff --git a/client/Command/ListConfigs/Makefile.am b/client/Command/ListConfigs/Makefile.am
new file mode 100644 (file)
index 0000000..c8cf730
--- /dev/null
@@ -0,0 +1,19 @@
+#
+# Makefile.am for snapper/client/Command/ListConfigs
+#
+
+SUBDIRS = SnappersData
+
+AM_CPPFLAGS = -I$(top_srcdir) $(DBUS_CFLAGS)
+
+noinst_LTLIBRARIES = libcommandlistconfigs.la
+
+libcommandlistconfigs_la_SOURCES =             \
+       Options.cc              Options.h       \
+       SnappersData.cc         SnappersData.h
+
+libcommandlistconfigs_la_LIBADD =      \
+       ../../../snapper/libsnapper.la  \
+       ../../utils/libutils.la         \
+       ../../../dbus/libdbus.la        \
+       SnappersData/libcommandlistconfigssnappersdata.la
diff --git a/client/Command/ListConfigs/Options.cc b/client/Command/ListConfigs/Options.cc
new file mode 100644 (file)
index 0000000..8403e99
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * 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 <boost/algorithm/string.hpp>
+
+#include "client/Command/ListConfigs/Options.h"
+#include "client/utils/text.h"
+
+using namespace std;
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       namespace
+       {
+
+           const option OPTIONS[] = {
+               { "columns",    required_argument,      0,      0},
+               { 0, 0, 0, 0 }
+           };
+
+       }
+
+
+       const string Command::ListConfigs::Options::Columns::CONFIG = "config";
+       const string Command::ListConfigs::Options::Columns::SUBVOLUME = "subvolume";
+
+
+       const vector<string> Command::ListConfigs::Options::ALL_COLUMNS = {
+           Columns::CONFIG,
+           Columns::SUBVOLUME
+       };
+
+
+       string Command::ListConfigs::Options::help_text()
+       {
+           return _("    Options for 'list-configs' command:\n"
+                    "\t--columns <columns>\t\tColumns to show separated by comma.\n"
+                    "\t\t\t\t\tPossible columns: config, subvolume.\n");
+       }
+
+
+       Command::ListConfigs::Options::Options(GetOpts& parser) :
+           cli::Options(parser), _columns_option(ALL_COLUMNS)
+       {
+           parse_options();
+
+           _columns_option.set_raw_columns(columns_raw());
+       }
+
+
+       void Command::ListConfigs::Options::parse_options()
+       {
+           _options = _parser.parse("list-configs", OPTIONS);
+       }
+
+
+       vector<string> Command::ListConfigs::Options::columns() const
+       {
+           if (has_option("columns"))
+               return _columns_option.selected_columns();
+
+           return { Columns::CONFIG, Columns::SUBVOLUME };
+       }
+
+
+       vector<string> Command::ListConfigs::Options::errors() const
+       {
+           vector<string> detected_errors;
+
+           if (!_columns_option.wrong_columns().empty())
+               detected_errors.push_back(_columns_option.error());
+
+           return detected_errors;
+       }
+
+
+       string Command::ListConfigs::Options::columns_raw() const
+       {
+           return has_option("columns") ? get_option("columns")->second : "";
+       }
+
+    }
+}
diff --git a/client/Command/ListConfigs/Options.h b/client/Command/ListConfigs/Options.h
new file mode 100644 (file)
index 0000000..531e8dd
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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_LIST_CONFIGS_OPTIONS_H
+#define SNAPPER_CLI_COMMAND_LIST_CONFIGS_OPTIONS_H
+
+#include "client/Options.h"
+#include "client/Command/ListConfigs.h"
+#include "client/Command/ColumnsOption.h"
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       class Command::ListConfigs::Options : public cli::Options
+       {
+
+       public:
+
+           struct Columns
+           {
+               static const std::string CONFIG;
+               static const std::string SUBVOLUME;
+           };
+
+           static const std::vector<std::string> ALL_COLUMNS;
+
+           static std::string help_text();
+
+           Options(GetOpts& parser);
+
+           std::vector<std::string> columns() const;
+
+           virtual std::vector<std::string> errors() const override;
+
+       private:
+
+           void parse_options();
+
+           string columns_raw() const;
+
+           Command::ColumnsOption _columns_option;
+
+       };
+
+    }
+}
+
+#endif
diff --git a/client/Command/ListConfigs/SnappersData.cc b/client/Command/ListConfigs/SnappersData.cc
new file mode 100644 (file)
index 0000000..2d4da19
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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/ListConfigs.h"
+#include "client/Command/ListConfigs/Options.h"
+#include "client/Command/ListConfigs/SnappersData.h"
+
+using namespace std;
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       Command::ListConfigs::SnappersData::SnappersData(const Command::ListConfigs& command) :
+           _command(command)
+       {}
+
+
+       Command::ListConfigs::SnappersData::~SnappersData()
+       {}
+
+
+       string Command::ListConfigs::SnappersData::value_for(const string& column,
+           ProxySnapper* snapper) const
+       {
+           if (column == Options::Columns::CONFIG)
+               return snapper->configName();
+
+           if (column == Options::Columns::SUBVOLUME)
+               return snapper->getConfig().getSubvolume();
+
+           return "";
+       }
+
+
+       vector<ProxySnapper*> Command::ListConfigs::SnappersData::snappers() const
+       {
+           vector<ProxySnapper*> snappers;
+
+           for (auto config_name : configs())
+           {
+               ProxySnapper* snapper = _command.snappers().getSnapper(config_name);
+
+               snappers.push_back(snapper);
+           }
+
+           return snappers;
+       }
+
+
+       vector<string> Command::ListConfigs::SnappersData::configs() const
+       {
+           vector<string> names;
+
+           for (map<string, ProxyConfig>::value_type it : _command.snappers().getConfigs())
+               names.push_back(it.first);
+
+           return names;
+       }
+
+    }
+}
diff --git a/client/Command/ListConfigs/SnappersData.h b/client/Command/ListConfigs/SnappersData.h
new file mode 100644 (file)
index 0000000..ab581c9
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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_LIST_CONFIGS_SNAPPERS_DATA_H
+#define SNAPPER_CLI_COMMAND_LIST_CONFIGS_SNAPPERS_DATA_H
+
+#include <string>
+#include <vector>
+
+#include "client/Command/ListConfigs.h"
+#include "client/proxy.h"
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       class Command::ListConfigs::SnappersData
+       {
+
+       public:
+
+           class Table;
+
+           class Csv;
+
+           class Json;
+
+           SnappersData(const Command::ListConfigs& command);
+
+           virtual ~SnappersData();
+
+           virtual std::string output() const = 0;
+
+       protected:
+
+           std::string value_for(const std::string& column, ProxySnapper* snapper) const;
+
+           std::vector<ProxySnapper*> snappers() const;
+
+       private:
+
+           std::vector<std::string> configs() const;
+
+           const ListConfigs& _command;
+       };
+
+    }
+}
+
+#endif
diff --git a/client/Command/ListConfigs/SnappersData/Csv.cc b/client/Command/ListConfigs/SnappersData/Csv.cc
new file mode 100644 (file)
index 0000000..5bd9637
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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 <vector>
+
+#include "client/Command/ListConfigs/SnappersData/Csv.h"
+#include "client/Command/ListConfigs/Options.h"
+#include "client/utils/CsvFormatter.h"
+
+using namespace std;
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       Command::ListConfigs::SnappersData::Csv::Csv(
+           const Command::ListConfigs& command, const string separator) :
+          SnappersData(command), _separator(separator)
+       {}
+
+
+       std::string Command::ListConfigs::SnappersData::Csv::output() const
+       {
+           vector<string> columns;
+
+           vector<vector<string>> rows;
+
+           for (const string& column : _command.options().columns())
+               columns.push_back(column);
+
+           for (ProxySnapper* snapper : snappers())
+           {
+               vector<string> row;
+
+               for (const string& column : _command.options().columns())
+                   row.push_back(value_for(column, snapper));
+
+               rows.push_back(row);
+           }
+
+           CsvFormatter formatter(columns, rows, _separator);
+
+           return formatter.output();
+       }
+
+    }
+}
diff --git a/client/Command/ListConfigs/SnappersData/Csv.h b/client/Command/ListConfigs/SnappersData/Csv.h
new file mode 100644 (file)
index 0000000..220fdc1
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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_LIST_CONFIGS_SNAPPERS_DATA_CSV_H
+#define SNAPPER_CLI_COMMAND_LIST_CONFIGS_SNAPPERS_DATA_CSV_H
+
+#include <string>
+
+#include "client/Command/ListConfigs/SnappersData.h"
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       class Command::ListConfigs::SnappersData::Csv : public Command::ListConfigs::SnappersData
+       {
+
+       public:
+
+           Csv(const ListConfigs& command, const std::string separator);
+
+           virtual std::string output() const override;
+
+       private:
+
+           const std::string _separator;
+       };
+
+    }
+}
+
+#endif
diff --git a/client/Command/ListConfigs/SnappersData/Json.cc b/client/Command/ListConfigs/SnappersData/Json.cc
new file mode 100644 (file)
index 0000000..8206c0f
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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/ListConfigs/SnappersData/Json.h"
+#include "client/Command/ListConfigs/Options.h"
+#include "client/utils/JsonFormatter.h"
+
+using namespace std;
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       namespace
+       {
+
+           const string SNAPPERS_KEY = "configs";
+
+       }
+
+
+       std::string Command::ListConfigs::SnappersData::Json::output() const
+       {
+           JsonFormatter::Data data;
+
+           data.emplace_back(SNAPPERS_KEY, snappers_json());
+
+           JsonFormatter formatter(data);
+
+           formatter.skip_format_values({ SNAPPERS_KEY });
+
+           return formatter.output();
+       }
+
+
+       string
+       Command::ListConfigs::SnappersData::Json::snappers_json() const
+       {
+           vector<string> data;
+
+           for (ProxySnapper* snapper : snappers())
+           {
+               data.push_back(snapper_json(snapper));
+           }
+
+           JsonFormatter::List json_list(data);
+
+           return json_list.output(1);
+       }
+
+
+       string Command::ListConfigs::SnappersData::Json::snapper_json(ProxySnapper* snapper) const
+       {
+           JsonFormatter::Data data;
+
+           for (const string& column : _command.options().columns())
+               data.emplace_back(column, value_for(column, snapper));
+
+           JsonFormatter formatter(data);
+
+           return formatter.output(2);
+       }
+
+    }
+}
diff --git a/client/Command/ListConfigs/SnappersData/Json.h b/client/Command/ListConfigs/SnappersData/Json.h
new file mode 100644 (file)
index 0000000..0f10699
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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_LIST_CONFIGS_SNAPPERS_DATA_JSON_H
+#define SNAPPER_CLI_COMMAND_LIST_CONFIGS_SNAPPERS_DATA_JSON_H
+
+#include <vector>
+#include <string>
+
+#include "client/Command/ListConfigs/SnappersData.h"
+#include "client/proxy.h"
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       class Command::ListConfigs::SnappersData::Json : public Command::ListConfigs::SnappersData
+       {
+
+       public:
+
+           using Command::ListConfigs::SnappersData::SnappersData;
+
+           virtual std::string output() const override;
+
+       private:
+
+           std::string snappers_json() const;
+
+           std::string snapper_json(ProxySnapper* snapper) const;
+
+       };
+
+    }
+}
+
+#endif
diff --git a/client/Command/ListConfigs/SnappersData/Makefile.am b/client/Command/ListConfigs/SnappersData/Makefile.am
new file mode 100644 (file)
index 0000000..fd23dfe
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# Makefile.am for snapper/client/Command/ListConfigs/SnappersData
+#
+
+AM_CPPFLAGS = -I$(top_srcdir) $(DBUS_CFLAGS)
+
+noinst_LTLIBRARIES = libcommandlistconfigssnappersdata.la
+
+libcommandlistconfigssnappersdata_la_SOURCES = \
+       Table.cc        Table.h                 \
+       Csv.cc          Csv.h                   \
+       Json.cc         Json.h
+
+libcommandlistconfigssnappersdata_la_LIBADD =  \
+       ../../../../snapper/libsnapper.la       \
+       ../../../utils/libutils.la              \
+       ../../../../dbus/libdbus.la
diff --git a/client/Command/ListConfigs/SnappersData/Table.cc b/client/Command/ListConfigs/SnappersData/Table.cc
new file mode 100644 (file)
index 0000000..62f097b
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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/ListConfigs/SnappersData/Table.h"
+#include "client/Command/ListConfigs/Options.h"
+#include "client/utils/TableFormatter.h"
+#include "client/utils/text.h"
+
+using namespace std;
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       Command::ListConfigs::SnappersData::Table::Table(
+           const Command::ListConfigs& command, TableLineStyle style) :
+           SnappersData(command), _style(style)
+       {}
+
+
+       string Command::ListConfigs::SnappersData::Table::output() const
+       {
+           vector<pair<string, TableAlign>> columns;
+
+           vector<vector<string>> rows;
+
+           for (const string& column : _command.options().columns())
+               columns.emplace_back(label_for(column), TableAlign::LEFT);
+
+           for (ProxySnapper* snapper : snappers())
+           {
+               vector<string> row;
+
+               for (auto attribute : _command.options().columns())
+                   row.push_back(value_for(attribute, snapper));
+
+               rows.push_back(row);
+           }
+
+           TableFormatter formatter(columns, rows, _style);
+
+           return formatter.output();
+       }
+
+
+       string Command::ListConfigs::SnappersData::Table::label_for(const string& column) const
+       {
+           if (column == Options::Columns::CONFIG)
+               return _("Config");
+
+           if (column == Options::Columns::SUBVOLUME)
+               return _("Subvolume");
+
+           return "";
+       }
+
+    }
+}
diff --git a/client/Command/ListConfigs/SnappersData/Table.h b/client/Command/ListConfigs/SnappersData/Table.h
new file mode 100644 (file)
index 0000000..13d2aee
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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_LIST_CONFIGS_SNAPPERS_DATA_TABLE_H
+#define SNAPPER_CLI_COMMAND_LIST_CONFIGS_SNAPPERS_DATA_TABLE_H
+
+#include <string>
+
+#include "client/Command/ListConfigs/SnappersData.h"
+#include "client/utils/Table.h"
+
+namespace snapper
+{
+    namespace cli
+    {
+
+       class Command::ListConfigs::SnappersData::Table : public Command::ListConfigs::SnappersData
+       {
+
+       public:
+
+           Table(const ListConfigs& command, TableLineStyle style);
+
+           virtual std::string output() const override;
+
+       private:
+
+           std::string label_for(const std::string& column) const;
+
+           TableLineStyle _style;
+
+       };
+
+    }
+}
+
+#endif