[Updated] D8613: rhg: add a limited `rhg root` subcommand
acezar (Antoine Cezar)
phabricator at mercurial-scm.org
Wed Jun 24 13:05:33 UTC 2020
acezar edited the summary of this revision.
acezar marked an inline comment as done.
acezar updated this revision to Diff 21698.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8613?vs=21643&id=21698
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8613/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8613
AFFECTED FILES
rust/Cargo.lock
rust/rhg/Cargo.toml
rust/rhg/src/main.rs
rust/rhg/tests/test-root.t
rust/rhg/tests/test_t.rs
CHANGE DETAILS
diff --git a/rust/rhg/tests/test_t.rs b/rust/rhg/tests/test_t.rs
new file mode 100644
--- /dev/null
+++ b/rust/rhg/tests/test_t.rs
@@ -0,0 +1,16 @@
+use std::path::Path;
+use std::process::Command;
+
+#[test]
+fn test_root() {
+ let rhg_path = Path::new("../target/debug/rhg").canonicalize().unwrap();
+ println!("{:?}", &rhg_path);
+ let status = Command::new("../../tests/run-tests.py")
+ .arg("-l")
+ .arg("./tests/test-root.t")
+ .env("RHG", &rhg_path)
+ .status()
+ .unwrap();
+
+ assert!(status.success())
+}
diff --git a/rust/rhg/tests/test-root.t b/rust/rhg/tests/test-root.t
new file mode 100644
--- /dev/null
+++ b/rust/rhg/tests/test-root.t
@@ -0,0 +1,17 @@
+ $ alias rhg="$RHG"
+ $ rhg unimplemented-command
+ [252]
+ $ rhg root
+ abort: no repository found in '$TESTTMP' (.hg not found)!
+ [255]
+ $ hg init repository
+ $ cd repository
+ $ rhg root
+ $TESTTMP/repository
+ $ rhg root > /dev/full
+ abort: No space left on device (os error 28)
+ [255]
+ $ rm -rf $PWD
+ $ rhg root
+ abort: error getting current working directory: No such file or directory (os error 2)
+ [255]
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,8 +1,42 @@
+use clap::App;
+use clap::AppSettings;
+use clap::SubCommand;
+
mod commands;
mod error;
mod exitcode;
mod ui;
+use commands::Command;
fn main() {
- std::process::exit(exitcode::UNIMPLEMENTED_COMMAND)
+ let mut app = App::new("rhg")
+ .setting(AppSettings::AllowInvalidUtf8)
+ .setting(AppSettings::SubcommandRequired)
+ .setting(AppSettings::VersionlessSubcommands)
+ .version("0.0.1")
+ .subcommand(
+ SubCommand::with_name("root").about(commands::root::HELP_TEXT),
+ );
+
+ let matches = app.clone().get_matches_safe().unwrap_or_else(|_| {
+ std::process::exit(exitcode::UNIMPLEMENTED_COMMAND)
+ });
+
+ let command_result = match matches.subcommand_name() {
+ Some(name) => match name {
+ "root" => commands::root::RootCommand::new().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) => e.exit(),
+ }
}
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, Alphare
Cc: marmoute, Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200624/42d5ee1a/attachment-0002.html>
More information about the Mercurial-patches
mailing list