diff --git a/remwharead.1.adoc b/remwharead.1.adoc index 94b00e3..43afa0d 100644 --- a/remwharead.1.adoc +++ b/remwharead.1.adoc @@ -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 moment. +*-S* _attribute_, *--sort* _attribute_:: +Sort by _time_, _tag_ or _both_ (default) when exporting to _asciidoc_. + *-h*, *--help*:: Show help message. @@ -55,7 +58,7 @@ Print version, copyright and license. == FILES -* *Database*: `${XDG_DATA_HOME}/remwharead.sqlite` +* *Database*: `${XDG_DATA_HOME}/remwharead/database.sqlite` `${XDG_DATA_HOME}` is usually `~/.local/share`. diff --git a/src/parse_options.cpp b/src/parse_options.cpp index b9ac81d..597f533 100644 --- a/src/parse_options.cpp +++ b/src/parse_options.cpp @@ -37,6 +37,7 @@ const options parse_options(const int argc, const char *argv[]) string format; string file; string span; + string sort; options opts; try @@ -51,6 +52,8 @@ const options parse_options(const int argc, const char *argv[]) op.add> ("s", "span", "Only export entries between YYYY-MM-DD,YYYY-MM-DD.", "", &span); + op.add> + ("S", "sort", "Sort by time, tag or both (default).", "", &sort); auto option_help = op.add ("h", "help", "Show this help message."); auto option_version = op.add @@ -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) { opts.url = op.non_option_args().front(); diff --git a/src/parse_options.hpp b/src/parse_options.hpp index 9905c99..d0a2cb0 100644 --- a/src/parse_options.hpp +++ b/src/parse_options.hpp @@ -37,12 +37,20 @@ enum class export_format asciidoc }; +enum class sort_attribute +{ + both, + time, + tag +}; + typedef struct options { vector tags; export_format format = export_format::undefined; string file; array span; + sort_attribute sort = sort_attribute::both; string url; uint8_t status_code = 0;