From d49016530f98df19b077b69b6cb4d61154623839 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 18 Jan 2020 13:44:17 +0200 Subject: bookmarks: implicitly append if export is not set --- src/bookmarks/builtins.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/bookmarks/builtins.cpp b/src/bookmarks/builtins.cpp index 8881038..259bfa6 100644 --- a/src/bookmarks/builtins.cpp +++ b/src/bookmarks/builtins.cpp @@ -16,13 +16,16 @@ int builtins::bookmarks(const std::string &progname, std::vector::const_iterator beginargs, std::vector::const_iterator endargs) { - args::ArgumentParser parser("bookmarks"); + args::ArgumentParser parser("bookmarks", + "If an output location is not specified, this command will append imported bookmarks to the browser's bookmarks.\n" + "If an output location is specified, this command will load all XBEL-format bookmarks, then all JSON-format bookmarks, and write them to the output location." + ); parser.Prog(progname); args::HelpFlag help(parser, "help", "Display this help message and exit.", { 'h', "help" }); - args::ValueFlag save(parser, "file, stdout", "Export the bookmarks as (defaults to bookmark path)", { 'e', "export" }); - args::ValueFlagList import_xbel(parser, "bookmarks.xbel", "Import xbel bookmarks", { 'x', "import-xbel" }); - args::ValueFlagList import_json(parser, "bookmarks.json", "Import json bookmarks", { 'j', "import-json" }); + args::ValueFlag save(parser, "file, stdout", "Output location.", { 'e', "export" }); + args::ValueFlagList import_xbel(parser, "bookmarks.xbel", "Import xbel format.", { 'x', "import-xbel" }); + args::ValueFlagList import_json(parser, "bookmarks.json", "Import json format.", { 'j', "import-json" }); try { parser.ParseArgs(beginargs, endargs); @@ -37,6 +40,16 @@ int builtins::bookmarks(const std::string &progname, std::vector::c auto *model = new BookmarkModel; + // implicit bookmarks.path import + if(!save) { + Configuration conf; + QFile f(conf.value("bookmarks.path").value()); + if(f.open(QIODevice::ReadOnly | QIODevice::Text)) { + BookmarkFormat(&f) >> model; + f.close(); + } + } + for(const auto &i : args::get(import_xbel)) { QFile f(QString::fromStdString(i)); if(f.open(QIODevice::ReadOnly | QIODevice::Text)) { -- cgit v1.2.1