Added --sort.

This commit is contained in:
tastytea 2019-05-14 22:56:58 +02:00
parent 8ec8a1a558
commit b7332de342
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 36 additions and 1 deletions

View File

@ -39,6 +39,9 @@ Only export entries between _start_ and _end_. _start_ and _end_ are date and
time representations according to ISO 8601. Time zones are ignored at the time representations according to ISO 8601. Time zones are ignored at the
moment. moment.
*-S* _attribute_, *--sort* _attribute_::
Sort by _time_, _tag_ or _both_ (default) when exporting to _asciidoc_.
*-h*, *--help*:: *-h*, *--help*::
Show help message. Show help message.
@ -55,7 +58,7 @@ Print version, copyright and license.
== FILES == FILES
* *Database*: `${XDG_DATA_HOME}/remwharead.sqlite` * *Database*: `${XDG_DATA_HOME}/remwharead/database.sqlite`
`${XDG_DATA_HOME}` is usually `~/.local/share`. `${XDG_DATA_HOME}` is usually `~/.local/share`.

View File

@ -37,6 +37,7 @@ const options parse_options(const int argc, const char *argv[])
string format; string format;
string file; string file;
string span; string span;
string sort;
options opts; options opts;
try try
@ -51,6 +52,8 @@ const options parse_options(const int argc, const char *argv[])
op.add<popl::Value<string>> op.add<popl::Value<string>>
("s", "span", "Only export entries between YYYY-MM-DD,YYYY-MM-DD.", ("s", "span", "Only export entries between YYYY-MM-DD,YYYY-MM-DD.",
"", &span); "", &span);
op.add<popl::Value<string>>
("S", "sort", "Sort by time, tag or both (default).", "", &sort);
auto option_help = op.add<popl::Switch> auto option_help = op.add<popl::Switch>
("h", "help", "Show this help message."); ("h", "help", "Show this help message.");
auto option_version = op.add<popl::Switch> auto option_version = op.add<popl::Switch>
@ -129,6 +132,27 @@ const options parse_options(const int argc, const char *argv[])
} }
} }
if (!sort.empty())
{
if (sort == "time")
{
opts.sort = sort_attribute::time;
}
else if (sort == "tag")
{
opts.sort = sort_attribute::tag;
}
else if (sort == "both")
{
opts.sort = sort_attribute::both;
}
else
{
cerr << "Error: --sort " << sort << " not understood.\n";
return options(1);
}
}
if (op.non_option_args().size() > 0) if (op.non_option_args().size() > 0)
{ {
opts.url = op.non_option_args().front(); opts.url = op.non_option_args().front();

View File

@ -37,12 +37,20 @@ enum class export_format
asciidoc asciidoc
}; };
enum class sort_attribute
{
both,
time,
tag
};
typedef struct options typedef struct options
{ {
vector<string> tags; vector<string> tags;
export_format format = export_format::undefined; export_format format = export_format::undefined;
string file; string file;
array<system_clock::time_point, 2> span; array<system_clock::time_point, 2> span;
sort_attribute sort = sort_attribute::both;
string url; string url;
uint8_t status_code = 0; uint8_t status_code = 0;