Forráskód Böngészése

docs: add example demonstrating new features in a partial implementation of a git command spec

Sam Jaffe 3 éve
szülő
commit
f206362a2d
1 módosított fájl, 53 hozzáadás és 0 törlés
  1. 53 0
      README.md

+ 53 - 0
README.md

@@ -19,6 +19,59 @@ Abbreviated options support key-value concatenation, such as how you can do `-I/
 
 #### Snippets
 
+A partial git command arguments:
+```c++
+struct Push : program::Arguments<Push> {
+  using Arguments::Arguments;
+  bool atomic = flag("atomic");
+  bool dry_run = flag("dry-run", 'n') = false;
+  bool no_verify = flag("no-verify", "skip push hooks") = false;
+  bool quiet = flag("quiet", 'q') = false;
+  bool verbose = flag("verbose", 'v') = false;
+  // ...more options
+  // TODO: Fetch Upstream Implicitly
+  std::string repository = argument(0, "repository") = "";
+  // TODO: Implement
+  std::vector<std::string> refspec = rest("refspec");
+};
+
+struct Pull : program::Arguments<Pull> {
+  using Arguments::Arguments;
+  bool quiet = flag("quiet", 'q') = false;
+  bool verbose = flag("verbose", 'v') = false;
+  bool commit = flag("commit", "immediately commit the merged result") = true;
+  bool edit = flag("edit", "edit the commit message before merging") = true;
+  bool fastforward = flag("ff", "resolve the merge with a fast-forward if possible") = true;
+  bool only_ff = flag("ff-only", "fail if fast-forwarding will not succeed");
+  // ...more options
+  // TODO: Fetch Upstream Implicitly
+  std::string repository = argument(0, "repository") = "";
+  // TODO: Implement
+  std::vector<std::string> refspec = arguments("refspec");
+};
+
+struct Commit : program::Arguments<Commit> {
+  using Arguments::Arguments;
+};
+
+struct Git : program::Arguments<Git> {
+public:
+  using Arguments::Arguments;
+  std::string pwd = option('C');
+  // TODO: Generator?
+  std::string git_dir = option("git-dir") = PROGRAM_DEFER(locate_git_dir(pwd));
+  std::map<std::string, std::string> config_env = option("config-env");
+  // ...more options
+private:
+  friend int main(int, char const * const*);
+  Commit commit = action("commit");
+  Push push = action("push");
+  Pull pull = action("pull");
+};
+
+TYPED_MAIN(Git)
+```
+
 Singular option storage cannot be repeated
 ```c++
 std::string directory = option("logdir");