@@ -5,7 +5,7 @@ use std::str::FromStr;
55
66use anyhow:: { anyhow, Error , Result } ;
77use clap:: {
8- builder:: { EnumValueParser , PossibleValue , PossibleValuesParser } ,
8+ builder:: { PossibleValue , PossibleValuesParser } ,
99 Arg , ArgAction , ArgMatches , Args , Command , FromArgMatches as _, Parser , Subcommand , ValueEnum ,
1010} ;
1111use clap_complete:: Shell ;
@@ -36,9 +36,8 @@ use crate::{
3636 toolchain:: {
3737 distributable:: DistributableToolchain ,
3838 names:: {
39- partial_toolchain_desc_parser, CustomToolchainName , LocalToolchainName ,
40- MaybeResolvableToolchainName , ResolvableLocalToolchainName , ResolvableToolchainName ,
41- ToolchainName ,
39+ CustomToolchainName , LocalToolchainName , MaybeResolvableToolchainName ,
40+ ResolvableLocalToolchainName , ResolvableToolchainName , ToolchainName ,
4241 } ,
4342 toolchain:: Toolchain ,
4443 } ,
@@ -206,6 +205,24 @@ enum RustupSubcmd {
206205 #[ command( flatten) ]
207206 page : DocPage ,
208207 } ,
208+
209+ /// View the man page for a given command
210+ #[ cfg( not( windows) ) ]
211+ Man {
212+ command : String ,
213+
214+ #[ arg( long, help = OFFICIAL_TOOLCHAIN_ARG_HELP ) ]
215+ toolchain : Option < PartialToolchainDesc > ,
216+ } ,
217+
218+ /// Generate tab-completion scripts for your shell
219+ #[ command( after_help = COMPLETIONS_HELP , arg_required_else_help = true ) ]
220+ Completions {
221+ shell : Shell ,
222+
223+ #[ arg( default_value = "rustup" ) ]
224+ command : CompletionCommand ,
225+ } ,
209226}
210227
211228#[ derive( Debug , Subcommand ) ]
@@ -504,6 +521,11 @@ impl Rustup {
504521 topic,
505522 page,
506523 } => doc ( cfg, path, toolchain, topic. as_deref ( ) , & page) ,
524+ #[ cfg( not( windows) ) ]
525+ RustupSubcmd :: Man { command, toolchain } => man ( cfg, & command, toolchain) ,
526+ RustupSubcmd :: Completions { shell, command } => {
527+ output_completion_script ( shell, command)
528+ }
507529 }
508530 }
509531}
@@ -582,11 +604,9 @@ pub fn main() -> Result<utils::ExitCode> {
582604 (
583605 "dump-testament" | "show" | "update" | "install" | "uninstall" | "toolchain"
584606 | "check" | "default" | "target" | "component" | "override" | "run" | "which"
585- | "doc" ,
607+ | "doc" | "man" | "completions" ,
586608 _,
587609 ) => Rustup :: from_arg_matches ( & matches) ?. dispatch ( cfg) ?,
588- #[ cfg( not( windows) ) ]
589- ( "man" , m) => man ( cfg, m) ?,
590610 ( "self" , c) => match c. subcommand ( ) {
591611 Some ( s) => match s {
592612 ( "update" , _) => self_update:: update ( cfg) ?,
@@ -604,18 +624,6 @@ pub fn main() -> Result<utils::ExitCode> {
604624 } ,
605625 None => unreachable ! ( ) ,
606626 } ,
607- ( "completions" , c) => {
608- if let Some ( & shell) = c. get_one :: < Shell > ( "shell" ) {
609- output_completion_script (
610- shell,
611- c. get_one :: < CompletionCommand > ( "command" )
612- . copied ( )
613- . unwrap_or ( CompletionCommand :: Rustup ) ,
614- ) ?
615- } else {
616- unreachable ! ( )
617- }
618- }
619627 _ => unreachable ! ( ) ,
620628 } ,
621629 None => {
@@ -626,7 +634,7 @@ pub fn main() -> Result<utils::ExitCode> {
626634}
627635
628636pub ( crate ) fn cli ( ) -> Command {
629- let mut app = Command :: new ( "rustup" )
637+ let app = Command :: new ( "rustup" )
630638 . version ( common:: version ( ) )
631639 . about ( "The Rust toolchain installer" )
632640 . before_help ( format ! ( "rustup {}" , common:: version( ) ) )
@@ -654,24 +662,7 @@ pub(crate) fn cli() -> Command {
654662 Err ( Error :: raw ( ErrorKind :: InvalidSubcommand , format ! ( "\" {s}\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. {TOOLCHAIN_OVERRIDE_ERROR}" ) ) )
655663 }
656664 } ) ,
657- ) ;
658-
659- if cfg ! ( not( target_os = "windows" ) ) {
660- app = app. subcommand (
661- Command :: new ( "man" )
662- . about ( "View the man page for a given command" )
663- . arg ( Arg :: new ( "command" ) . required ( true ) )
664- . arg (
665- Arg :: new ( "toolchain" )
666- . help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
667- . long ( "toolchain" )
668- . num_args ( 1 )
669- . value_parser ( partial_toolchain_desc_parser) ,
670- ) ,
671- ) ;
672- }
673-
674- app = app
665+ )
675666 . subcommand (
676667 Command :: new ( "self" )
677668 . about ( "Modify the rustup installation" )
@@ -717,18 +708,6 @@ pub(crate) fn cli() -> Command {
717708 . default_value ( SelfUpdateMode :: default_mode ( ) ) ,
718709 ) ,
719710 ) ,
720- )
721- . subcommand (
722- Command :: new ( "completions" )
723- . about ( "Generate tab-completion scripts for your shell" )
724- . after_help ( COMPLETIONS_HELP )
725- . arg_required_else_help ( true )
726- . arg ( Arg :: new ( "shell" ) . value_parser ( EnumValueParser :: < Shell > :: new ( ) ) )
727- . arg (
728- Arg :: new ( "command" )
729- . value_parser ( EnumValueParser :: < CompletionCommand > :: new ( ) )
730- . default_missing_value ( "rustup" ) ,
731- ) ,
732711 ) ;
733712
734713 RustupSubcmd :: augment_subcommands ( app)
@@ -1291,16 +1270,6 @@ fn component_remove(
12911270 Ok ( utils:: ExitCode ( 0 ) )
12921271}
12931272
1294- // Make *sure* only to use this for a subcommand whose "toolchain" argument
1295- // has .value_parser(partial_toolchain_desc_parser), or it will panic.
1296- // FIXME: Delete this.
1297- fn explicit_desc_or_dir_toolchain_old < ' a > ( cfg : & ' a Cfg , m : & ArgMatches ) -> Result < Toolchain < ' a > > {
1298- let toolchain = m
1299- . get_one :: < PartialToolchainDesc > ( "toolchain" )
1300- . map ( Into :: into) ;
1301- explicit_or_dir_toolchain2 ( cfg, toolchain)
1302- }
1303-
13041273fn explicit_desc_or_dir_toolchain (
13051274 cfg : & Cfg ,
13061275 toolchain : Option < PartialToolchainDesc > ,
@@ -1546,12 +1515,14 @@ fn doc(
15461515}
15471516
15481517#[ cfg( not( windows) ) ]
1549- fn man ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1518+ fn man (
1519+ cfg : & Cfg ,
1520+ command : & str ,
1521+ toolchain : Option < PartialToolchainDesc > ,
1522+ ) -> Result < utils:: ExitCode > {
15501523 use crate :: currentprocess:: varsource:: VarSource ;
15511524
1552- let command = m. get_one :: < String > ( "command" ) . unwrap ( ) ;
1553-
1554- let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1525+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, toolchain) ?;
15551526 let mut path = toolchain. path ( ) . to_path_buf ( ) ;
15561527 path. push ( "share" ) ;
15571528 path. push ( "man" ) ;
0 commit comments