3 #include "private/cli/commandmap.hpp"
4 #include "private/cli/common.hpp"
5 #include <sdl/syncstorage.hpp>
7 using namespace shareddatalayer;
8 using namespace shareddatalayer::cli;
12 std::shared_ptr<shareddatalayer::SyncStorage> createSyncStorage(const SyncStorage::Namespace& ns,
17 auto sdl(shareddatalayer::SyncStorage::create());
18 sdl->waitReady(ns, std::chrono::minutes(1));
21 catch (const shareddatalayer::Exception& error)
23 out << "SyncStorage create failed: " << error.what() << std::endl;
29 void get(shareddatalayer::SyncStorage& sdl,
30 const SyncStorage::Namespace& ns,
31 const SyncStorage::Key& key,
36 auto data(sdl.get(ns, {key}));
37 out << data << std::endl;
39 catch (const shareddatalayer::Exception& error)
41 out << "get(" << ns << ", " << key << ") failed: "
42 << error.what() << std::endl;
46 int getCommand(std::ostream& out, const boost::program_options::variables_map& map)
48 auto ns(map["ns"].as<std::string>());
49 auto key(map["key"].as<std::string>());
51 auto sdl(createSyncStorage(ns, out));
54 sdl->setOperationTimeout(std::chrono::seconds(5));
56 get(std::ref(*sdl), ns, key, out);
62 const char *longHelpGetCmd =
63 "Use get SDL API to read data from storage under the namespace.\n\n"
64 "Example: sdltool get --ns 'sdltool' --key 'key1'";
66 AUTO_REGISTER_COMMAND(std::bind(getCommand, std::placeholders::_1, std::placeholders::_3),
68 "get data with SDL API under the namespace",
70 CommandMap::Category::UTIL,
72 ("ns,n", boost::program_options::value<std::string>()->default_value("sdltoolns"), "namespace to use")
73 ("key,k", boost::program_options::value<std::string>()->default_value("key1"), "key value")