##// END OF EJS Templates
chg: fallback to original hg if stdio fds are missing...
chg: fallback to original hg if stdio fds are missing If stdio fds are missing (ex. fd 0 is not present), chg might open fds that take the numbers 0, and attachio would send the wrong fds to the client, which might cause unwanted behaviors. Avoid that by detecting the missing fds and falling back to the original hg. Differential Revision: https://phab.mercurial-scm.org/D9058

File last commit:

r46011:a6a000ab default
r46093:5eee6f4f default
Show More
main.rs
58 lines | 1.7 KiB | application/rls-services+xml | RustLexer
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 use clap::App;
use clap::AppSettings;
use clap::SubCommand;
Antoine Cezar
rhg: add Command trait for subcommands implemented by rhg...
r45515 mod commands;
mod error;
Antoine Cezar
rhg: add rhg crate...
r45503 mod exitcode;
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 mod ui;
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 use commands::Command;
Antoine Cezar
rhg: add rhg crate...
r45503
fn main() {
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 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),
Antoine Cezar
rhg: add a limited `rhg files` subcommand...
r45924 )
.subcommand(
SubCommand::with_name("files").about(commands::files::HELP_TEXT),
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 );
Antoine Cezar
rhg: print error message when argument parsing fails...
r46011 let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
let _ = ui::Ui::new().writeln_stderr_str(&err.message);
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 std::process::exit(exitcode::UNIMPLEMENTED_COMMAND)
});
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 let ui = ui::Ui::new();
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 let command_result = match matches.subcommand_name() {
Some(name) => match name {
Antoine Cezar
rhg: pass `ui` to `Command` `run`...
r46009 "root" => commands::root::RootCommand::new().run(&ui),
"files" => commands::files::FilesCommand::new().run(&ui),
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 _ => 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),
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 Err(e) => {
let message = e.get_error_message_bytes();
if let Some(msg) = message {
match ui.write_stderr(&msg) {
Ok(_) => (),
Err(_) => std::process::exit(exitcode::ABORT),
};
};
e.exit()
}
Antoine Cezar
rhg: add a limited `rhg root` subcommand...
r45593 }
Antoine Cezar
rhg: add rhg crate...
r45503 }