[Request] [+- ] D8613: rhg: add a limited `rhg root` subcommand

acezar (Antoine Cezar) phabricator at mercurial-scm.org
Fri Jun 5 14:32:40 UTC 2020


acezar created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Clap has been choosen for argument parsing for the following reasons:
  
  - it's a wild used and maintained crate
  - it can deal with bytes making it suitable for any encoding
  - it supports nonambiguous prefix matching as already available in hg
  - it will soon allow for structopts-style declarative pattern instead of the currently used builder pattern

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8613

AFFECTED FILES
  rust/Cargo.lock
  rust/rhg/Cargo.toml
  rust/rhg/src/main.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -1,7 +1,32 @@
+use clap::App;
+use clap::SubCommand;
+
 mod commands;
 mod error;
 mod exitcode;
+use commands::Command;
 
 fn main() {
-    std::process::exit(exitcode::UNIMPLEMENTED_COMMAND)
+    let mut app = App::new("rhg").version("0.0.1").subcommand(
+        SubCommand::with_name("root").about(commands::root::HELP_TEXT),
+    );
+    let matches = app.clone().get_matches();
+
+    let command_result = match matches.subcommand_name() {
+        Some(name) => match name {
+            "root" => commands::root::RootCommand::run(),
+            _ => std::process::exit(exitcode::UNIMPLEMENTED_COMMAND),
+        },
+        _ => {
+            match app.print_help() {
+                Ok(_) => std::process::exit(exitcode::OK),
+                Err(_) => std::process::exit(exitcode::ABORT),
+            };
+        }
+    };
+
+    match command_result {
+        Ok(_) => std::process::exit(exitcode::OK),
+        Err(e) => std::process::exit(e.kind.get_exit_code()),
+    }
 }
diff --git a/rust/rhg/Cargo.toml b/rust/rhg/Cargo.toml
--- a/rust/rhg/Cargo.toml
+++ b/rust/rhg/Cargo.toml
@@ -6,4 +6,5 @@
 
 [dependencies]
 hg-core = { path = "../hg-core"}
+clap = "2.33.1"
 
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -58,7 +58,7 @@
 
 [[package]]
 name = "clap"
-version = "2.33.0"
+version = "2.33.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -203,7 +203,7 @@
 version = "0.1.0"
 dependencies = [
  "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -490,6 +490,7 @@
 name = "rhg"
 version = "0.1.0"
 dependencies = [
+ "clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "hg-core 0.1.0",
 ]
 
@@ -657,7 +658,7 @@
 "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
 "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
 "checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
-"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
+"checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
 "checksum colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
 "checksum cpython 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfaf3847ab963e40c4f6dd8d6be279bdf74007ae2413786a0dcbb28c52139a95"
 "checksum crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e"



To: acezar, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200605/2f3afca8/attachment-0001.html>


More information about the Mercurial-patches mailing list