Ver Fonte

fix: make CLI non-copyable and non-movable

chore: update string_utils to 1.0.1

docs: add simple readme
Sam Jaffe há 2 anos atrás
pai
commit
6855a60aa4
5 ficheiros alterados com 18 adições e 5 exclusões
  1. 5 0
      README.md
  2. 2 0
      cli.xcodeproj/project.pbxproj
  3. 1 1
      external/string-utils
  4. 9 3
      include/cli/cli.h
  5. 1 1
      src/cli.cxx

+ 5 - 0
README.md

@@ -0,0 +1,5 @@
+#  Command-Line Interface Library
+
+A utility library for defining a CLI inside of a program, allowing for stateful operations.
+
+Commands are registered as either `queries` (which fetch and print some state/information), or as `callbacks`, which perform some action.

+ 2 - 0
cli.xcodeproj/project.pbxproj

@@ -81,6 +81,7 @@
 
 /* Begin PBXFileReference section */
 		CD7B8B7825E2946900867188 /* xcode_gtest_helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xcode_gtest_helper.h; sourceTree = "<group>"; };
+		CD87CDAE29BE022900C5949D /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
 		CDC748A52531353C008D9D1D /* libcli.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcli.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDC748AC25313553008D9D1D /* GoogleMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GoogleMock.xcodeproj; path = "../../../gmock-xcode-master/GoogleMock.xcodeproj"; sourceTree = "<group>"; };
 		CDC748BD25313587008D9D1D /* cli */ = {isa = PBXFileReference; lastKnownFileType = folder; name = cli; path = include/cli; sourceTree = "<group>"; };
@@ -121,6 +122,7 @@
 		CDC7489C2531353C008D9D1D = {
 			isa = PBXGroup;
 			children = (
+				CD87CDAE29BE022900C5949D /* README.md */,
 				CDC748EA25314195008D9D1D /* string-utils.xcodeproj */,
 				CDC748AC25313553008D9D1D /* GoogleMock.xcodeproj */,
 				CDC748BD25313587008D9D1D /* cli */,

+ 1 - 1
external/string-utils

@@ -1 +1 @@
-Subproject commit 057f98396ed68a63603e25dc98d981dd9232d44f
+Subproject commit 545cac400532054bbe0b87bbdc20d2b060ce3456

+ 9 - 3
include/cli/cli.h

@@ -35,8 +35,9 @@ private:
   bool eof_;
 
 public:
-  cli(std::string const & prompt, std::istream &in = std::cin);
-  cli(std::istream &in = std::cin);
+  explicit cli(std::string const & prompt, std::istream &in = std::cin);
+  explicit cli(std::istream &in = std::cin);
+
   template <typename... Args>
   cli & register_callback(std::string const & handle,
                           std::function<void(Args...)> cb);
@@ -55,13 +56,18 @@ public:
   
 private:
   bool active() const;
+  
+  cli(cli const &) = delete;
+  cli(cli &&) = delete;
+  cli &operator=(cli const &) = delete;
+  cli &operator=(cli &&) = delete;
 };
 
 template <typename... Args, size_t... Is>
 void cli_invoke(std::function<void(Args...)> cb, cli::args_t const & args,
                 std::index_sequence<Is...>) {
   std::tuple<std::decay_t<Args>...> object;
-  if (string_utils::cast(args, object)) {
+  if (string_utils::cast(object, args)) {
     cb(std::move(std::get<Is>(object))...);
   }
 }

+ 1 - 1
src/cli.cxx

@@ -35,7 +35,7 @@ bool cli::active() const {
 void cli::run() const {
   std::string command;
   while (active() && std::getline(in_, command)) {
-    auto split = string_utils::tokenizer(" ", {'"', "\\\""}).escapable(true);
+    auto split = string_utils::EscapedTokenizer(" ", {'"', "\\\""});
     auto views = split(command);
     command = views.front();
     views.erase(views.begin());