Added “simple” export.
This commit is contained in:
parent
4406a8c64d
commit
71bce0c87d
14
src/main.cpp
14
src/main.cpp
|
@ -27,6 +27,7 @@
|
||||||
#include "csv.hpp"
|
#include "csv.hpp"
|
||||||
#include "adoc.hpp"
|
#include "adoc.hpp"
|
||||||
#include "bookmarks.hpp"
|
#include "bookmarks.hpp"
|
||||||
|
#include "simple.hpp"
|
||||||
#include "search.hpp"
|
#include "search.hpp"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
@ -135,6 +136,19 @@ int main(const int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case export_format::simple:
|
||||||
|
{
|
||||||
|
if (file.is_open())
|
||||||
|
{
|
||||||
|
Export::Simple(entries, file).print();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Export::Simple(entries).print();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -43,8 +43,8 @@ const options parse_options(const int argc, const char *argv[])
|
||||||
popl::OptionParser op("Available options");
|
popl::OptionParser op("Available options");
|
||||||
op.add<popl::Value<string>>
|
op.add<popl::Value<string>>
|
||||||
("t", "tags", "Add tags to URI, delimited by commas.", "", &tags);
|
("t", "tags", "Add tags to URI, delimited by commas.", "", &tags);
|
||||||
op.add<popl::Value<string>>
|
auto option_export = op.add<popl::Implicit<string>>
|
||||||
("e", "export", "Export to format.", "", &format);
|
("e", "export", "Export to format.", "simple", &format);
|
||||||
op.add<popl::Value<string>>
|
op.add<popl::Value<string>>
|
||||||
("f", "file", "Save output to file.", "", &opts.file);
|
("f", "file", "Save output to file.", "", &opts.file);
|
||||||
op.add<popl::Value<string>>
|
op.add<popl::Value<string>>
|
||||||
|
@ -113,7 +113,7 @@ const options parse_options(const int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!format.empty())
|
if (option_export->is_set())
|
||||||
{
|
{
|
||||||
if (format == "csv")
|
if (format == "csv")
|
||||||
{
|
{
|
||||||
|
@ -127,11 +127,15 @@ const options parse_options(const int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
opts.format = export_format::bookmarks;
|
opts.format = export_format::bookmarks;
|
||||||
}
|
}
|
||||||
|
else if (format == "simple")
|
||||||
|
{
|
||||||
|
opts.format = export_format::simple;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
opts.format = export_format::undefined;
|
opts.format = export_format::undefined;
|
||||||
cerr << "Error: Export format must be "
|
cerr << "Error: Export format must be "
|
||||||
<< "csv, asciidoc or bookmarks.\n";
|
<< "csv, asciidoc, bookmarks or simple.\n";
|
||||||
return options(1);
|
return options(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* This file is part of remwharead.
|
||||||
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "sqlite.hpp"
|
||||||
|
#include "time.hpp"
|
||||||
|
#include "simple.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
void Export::Simple::print() const
|
||||||
|
{
|
||||||
|
for (const Database::entry & entry : _entries)
|
||||||
|
{
|
||||||
|
const string timestring = timepoint_to_string(entry.datetime);
|
||||||
|
_out << timestring.substr(0, timestring.find('T')) << ": ";
|
||||||
|
if (!entry.title.empty())
|
||||||
|
{
|
||||||
|
_out << entry.title << '\n';
|
||||||
|
_out << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
_out << "<" << entry.uri << ">\n";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* This file is part of remwharead.
|
||||||
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef REMWHAREAD_SIMPLE_HPP
|
||||||
|
#define REMWHAREAD_SIMPLE_HPP
|
||||||
|
|
||||||
|
#include "export.hpp"
|
||||||
|
|
||||||
|
namespace Export
|
||||||
|
{
|
||||||
|
//! Export as simple list.
|
||||||
|
class Simple : protected ExportBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using ExportBase::ExportBase;
|
||||||
|
virtual void print() const override;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // REMWHAREAD_SIMPLE_HPP
|
|
@ -22,7 +22,8 @@ enum class export_format
|
||||||
undefined,
|
undefined,
|
||||||
csv,
|
csv,
|
||||||
asciidoc,
|
asciidoc,
|
||||||
bookmarks
|
bookmarks,
|
||||||
|
simple
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REMWHAREAD_TYPES_HPP
|
#endif // REMWHAREAD_TYPES_HPP
|
||||||
|
|
Loading…
Reference in New Issue