@@ -5,7 +5,7 @@ use std::str::FromStr;
5
5
6
6
use anyhow:: { anyhow, Error , Result } ;
7
7
use clap:: {
8
- builder:: { EnumValueParser , PossibleValue , PossibleValuesParser } ,
8
+ builder:: { PossibleValue , PossibleValuesParser } ,
9
9
Arg , ArgAction , ArgMatches , Args , Command , FromArgMatches as _, Parser , Subcommand , ValueEnum ,
10
10
} ;
11
11
use clap_complete:: Shell ;
@@ -36,9 +36,8 @@ use crate::{
36
36
toolchain:: {
37
37
distributable:: DistributableToolchain ,
38
38
names:: {
39
- partial_toolchain_desc_parser, CustomToolchainName , LocalToolchainName ,
40
- MaybeResolvableToolchainName , ResolvableLocalToolchainName , ResolvableToolchainName ,
41
- ToolchainName ,
39
+ CustomToolchainName , LocalToolchainName , MaybeResolvableToolchainName ,
40
+ ResolvableLocalToolchainName , ResolvableToolchainName , ToolchainName ,
42
41
} ,
43
42
toolchain:: Toolchain ,
44
43
} ,
@@ -206,6 +205,24 @@ enum RustupSubcmd {
206
205
#[ command( flatten) ]
207
206
page : DocPage ,
208
207
} ,
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
+ } ,
209
226
}
210
227
211
228
#[ derive( Debug , Subcommand ) ]
@@ -504,6 +521,11 @@ impl Rustup {
504
521
topic,
505
522
page,
506
523
} => 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
+ }
507
529
}
508
530
}
509
531
}
@@ -582,11 +604,9 @@ pub fn main() -> Result<utils::ExitCode> {
582
604
(
583
605
"dump-testament" | "show" | "update" | "install" | "uninstall" | "toolchain"
584
606
| "check" | "default" | "target" | "component" | "override" | "run" | "which"
585
- | "doc" ,
607
+ | "doc" | "man" | "completions" ,
586
608
_,
587
609
) => Rustup :: from_arg_matches ( & matches) ?. dispatch ( cfg) ?,
588
- #[ cfg( not( windows) ) ]
589
- ( "man" , m) => man ( cfg, m) ?,
590
610
( "self" , c) => match c. subcommand ( ) {
591
611
Some ( s) => match s {
592
612
( "update" , _) => self_update:: update ( cfg) ?,
@@ -604,18 +624,6 @@ pub fn main() -> Result<utils::ExitCode> {
604
624
} ,
605
625
None => unreachable ! ( ) ,
606
626
} ,
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
- }
619
627
_ => unreachable ! ( ) ,
620
628
} ,
621
629
None => {
@@ -626,7 +634,7 @@ pub fn main() -> Result<utils::ExitCode> {
626
634
}
627
635
628
636
pub ( crate ) fn cli ( ) -> Command {
629
- let mut app = Command :: new ( "rustup" )
637
+ let app = Command :: new ( "rustup" )
630
638
. version ( common:: version ( ) )
631
639
. about ( "The Rust toolchain installer" )
632
640
. before_help ( format ! ( "rustup {}" , common:: version( ) ) )
@@ -654,24 +662,7 @@ pub(crate) fn cli() -> Command {
654
662
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}" ) ) )
655
663
}
656
664
} ) ,
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
+ )
675
666
. subcommand (
676
667
Command :: new ( "self" )
677
668
. about ( "Modify the rustup installation" )
@@ -717,18 +708,6 @@ pub(crate) fn cli() -> Command {
717
708
. default_value ( SelfUpdateMode :: default_mode ( ) ) ,
718
709
) ,
719
710
) ,
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
- ) ,
732
711
) ;
733
712
734
713
RustupSubcmd :: augment_subcommands ( app)
@@ -1291,16 +1270,6 @@ fn component_remove(
1291
1270
Ok ( utils:: ExitCode ( 0 ) )
1292
1271
}
1293
1272
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
-
1304
1273
fn explicit_desc_or_dir_toolchain (
1305
1274
cfg : & Cfg ,
1306
1275
toolchain : Option < PartialToolchainDesc > ,
@@ -1546,12 +1515,14 @@ fn doc(
1546
1515
}
1547
1516
1548
1517
#[ 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 > {
1550
1523
use crate :: currentprocess:: varsource:: VarSource ;
1551
1524
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) ?;
1555
1526
let mut path = toolchain. path ( ) . to_path_buf ( ) ;
1556
1527
path. push ( "share" ) ;
1557
1528
path. push ( "man" ) ;
0 commit comments