Skip to content

Commit a555eb2

Browse files
authored
Merge pull request #616 from theindigamer/man-subcommand
Add man subcommand.
2 parents 383c58f + 6a86564 commit a555eb2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/rustup-cli/rustup_mode.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustup_dist::dist::{TargetTriple, PartialToolchainDesc, PartialTargetTriple}
88
use rustup_utils::utils;
99
use self_update;
1010
use std::path::Path;
11+
use std::process::Command;
1112
use std::iter;
1213
use term2;
1314
use std::io::Write;
@@ -69,6 +70,7 @@ pub fn main() -> Result<()> {
6970
("run", Some(m)) => try!(run(cfg, m)),
7071
("which", Some(m)) => try!(which(cfg, m)),
7172
("doc", Some(m)) => try!(doc(cfg, m)),
73+
("man", Some(m)) => try!(man(cfg,m)),
7274
("self", Some(c)) => {
7375
match c.subcommand() {
7476
("update", Some(_)) => try!(self_update::update()),
@@ -248,6 +250,13 @@ pub fn cli() -> App<'static, 'static> {
248250
.help("Standard library API documentation"))
249251
.group(ArgGroup::with_name("page")
250252
.args(&["book", "std"])))
253+
.subcommand(SubCommand::with_name("man")
254+
.about("View the man page for a given command")
255+
.arg(Arg::with_name("command")
256+
.required(true))
257+
.arg(Arg::with_name("toolchain")
258+
.long("toolchain")
259+
.takes_value(true)))
251260
.subcommand(SubCommand::with_name("self")
252261
.about("Modify the rustup installation")
253262
.setting(AppSettings::VersionlessSubcommands)
@@ -624,6 +633,22 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
624633
Ok(try!(cfg.open_docs_for_dir(&try!(utils::current_dir()), doc_url)))
625634
}
626635

636+
fn man(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
637+
let manpage = m.value_of("command").expect("");
638+
let toolchain = try!(explicit_or_dir_toolchain(cfg, m));
639+
let mut man_path = toolchain.path().to_path_buf();
640+
man_path.push("share");
641+
man_path.push("man");
642+
man_path.push("man1");
643+
man_path.push(manpage.to_owned() + ".1");
644+
try!(utils::assert_is_file(&man_path));
645+
Command::new("man")
646+
.arg(man_path)
647+
.status()
648+
.expect("failed to open man page");
649+
Ok(())
650+
}
651+
627652
fn self_uninstall(m: &ArgMatches) -> Result<()> {
628653
let no_prompt = m.is_present("no-prompt");
629654

0 commit comments

Comments
 (0)