[Updated] D8613: rhg: add a limited `rhg root` subcommand
acezar (Antoine Cezar)
phabricator at mercurial-scm.org
Mon Jun 29 08:21:29 UTC 2020
acezar updated this revision to Diff 21724.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8613?vs=21698&id=21724
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
tests/run-tests.py
tests/test-rhg.t
CHANGE DETAILS
diff --git a/tests/test-rhg.t b/tests/test-rhg.t
new file mode 100644
--- /dev/null
+++ b/tests/test-rhg.t
@@ -0,0 +1,16 @@
+ $ 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: $ENOENT$
+ [255]
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -927,6 +927,7 @@
extraconfigopts=None,
shell=None,
hgcommand=None,
+ rhgcommand=None,
slowtimeout=None,
usechg=False,
chgdebug=False,
@@ -984,6 +985,9 @@
self._extraconfigopts = extraconfigopts or []
self._shell = _sys2bytes(shell)
self._hgcommand = hgcommand or b'hg'
+ self._rhgcommand = rhgcommand or _sys2bytes(
+ os.path.abspath('./rust/target/release/rhg')
+ )
self._usechg = usechg
self._chgdebug = chgdebug
self._useipv6 = useipv6
@@ -1754,6 +1758,8 @@
script.append(b'set -x\n')
if self._hgcommand != b'hg':
script.append(b'alias hg="%s"\n' % self._hgcommand)
+ if self._rhgcommand != b'rhg':
+ script.append(b'alias rhg="%s"\n' % self._rhgcommand)
if os.getenv('MSYSTEM'):
script.append(b'alias pwd="pwd -W"\n')
@@ -2950,6 +2956,7 @@
self._coveragefile = None
self._createdfiles = []
self._hgcommand = None
+ self._rhgcommand = None
self._hgpath = None
self._portoffset = 0
self._ports = {}
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/20200629/b1d18e48/attachment-0002.html>
More information about the Mercurial-patches
mailing list