@@ -5,6 +5,7 @@ mod crate_spec;
5
5
use std:: collections:: BTreeMap ;
6
6
use std:: collections:: BTreeSet ;
7
7
use std:: collections:: VecDeque ;
8
+ use std:: fmt:: Write ;
8
9
use std:: path:: Path ;
9
10
10
11
use anyhow:: Context as _;
@@ -99,7 +100,8 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
99
100
table_option. map_or ( true , |table| is_sorted ( table. iter ( ) . map ( |( name, _) | name) ) )
100
101
} ) ;
101
102
for dep in deps {
102
- print_msg ( & mut options. config . shell ( ) , & dep, & dep_table) ?;
103
+ print_action_msg ( & mut options. config . shell ( ) , & dep, & dep_table) ?;
104
+ print_dep_table_msg ( & mut options. config . shell ( ) , & dep) ?;
103
105
if let Some ( Source :: Path ( src) ) = dep. source ( ) {
104
106
if src. path == manifest. path . parent ( ) . unwrap_or_else ( || Path :: new ( "" ) ) {
105
107
anyhow:: bail!(
@@ -634,6 +636,42 @@ impl DependencyUI {
634
636
} )
635
637
. collect ( ) ;
636
638
}
639
+
640
+ fn features ( & self ) -> ( IndexSet < & str > , IndexSet < & str > ) {
641
+ let mut activated: IndexSet < _ > =
642
+ self . features . iter ( ) . flatten ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
643
+ if self . default_features ( ) . unwrap_or ( true ) {
644
+ activated. insert ( "default" ) ;
645
+ }
646
+ activated. extend ( self . inherited_features . iter ( ) . flatten ( ) . map ( |s| s. as_str ( ) ) ) ;
647
+ let mut walk: VecDeque < _ > = activated. iter ( ) . cloned ( ) . collect ( ) ;
648
+ while let Some ( next) = walk. pop_front ( ) {
649
+ walk. extend (
650
+ self . available_features
651
+ . get ( next)
652
+ . into_iter ( )
653
+ . flatten ( )
654
+ . map ( |s| s. as_str ( ) ) ,
655
+ ) ;
656
+ activated. extend (
657
+ self . available_features
658
+ . get ( next)
659
+ . into_iter ( )
660
+ . flatten ( )
661
+ . map ( |s| s. as_str ( ) ) ,
662
+ ) ;
663
+ }
664
+ activated. remove ( "default" ) ;
665
+ activated. sort ( ) ;
666
+ let mut deactivated = self
667
+ . available_features
668
+ . keys ( )
669
+ . filter ( |f| !activated. contains ( f. as_str ( ) ) && * f != "default" )
670
+ . map ( |f| f. as_str ( ) )
671
+ . collect :: < IndexSet < _ > > ( ) ;
672
+ deactivated. sort ( ) ;
673
+ ( activated, deactivated)
674
+ }
637
675
}
638
676
639
677
impl < ' s > From < & ' s Summary > for DependencyUI {
@@ -697,9 +735,7 @@ fn populate_available_features(
697
735
Ok ( dependency)
698
736
}
699
737
700
- fn print_msg ( shell : & mut Shell , dep : & DependencyUI , section : & [ String ] ) -> CargoResult < ( ) > {
701
- use std:: fmt:: Write ;
702
-
738
+ fn print_action_msg ( shell : & mut Shell , dep : & DependencyUI , section : & [ String ] ) -> CargoResult < ( ) > {
703
739
if matches ! ( shell. verbosity( ) , crate :: core:: shell:: Verbosity :: Quiet ) {
704
740
return Ok ( ( ) ) ;
705
741
}
@@ -736,38 +772,14 @@ fn print_msg(shell: &mut Shell, dep: &DependencyUI, section: &[String]) -> Cargo
736
772
} ;
737
773
write ! ( message, " {section}" ) ?;
738
774
write ! ( message, "." ) ?;
739
- shell. status ( "Adding" , message) ?;
740
-
741
- let mut activated: IndexSet < _ > = dep. features . iter ( ) . flatten ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
742
- if dep. default_features ( ) . unwrap_or ( true ) {
743
- activated. insert ( "default" ) ;
744
- }
745
- activated. extend ( dep. inherited_features . iter ( ) . flatten ( ) . map ( |s| s. as_str ( ) ) ) ;
746
- let mut walk: VecDeque < _ > = activated. iter ( ) . cloned ( ) . collect ( ) ;
747
- while let Some ( next) = walk. pop_front ( ) {
748
- walk. extend (
749
- dep. available_features
750
- . get ( next)
751
- . into_iter ( )
752
- . flatten ( )
753
- . map ( |s| s. as_str ( ) ) ,
754
- ) ;
755
- activated. extend (
756
- dep. available_features
757
- . get ( next)
758
- . into_iter ( )
759
- . flatten ( )
760
- . map ( |s| s. as_str ( ) ) ,
761
- ) ;
775
+ shell. status ( "Adding" , message)
776
+ }
777
+
778
+ fn print_dep_table_msg ( shell : & mut Shell , dep : & DependencyUI ) -> CargoResult < ( ) > {
779
+ if matches ! ( shell. verbosity( ) , crate :: core:: shell:: Verbosity :: Quiet ) {
780
+ return Ok ( ( ) ) ;
762
781
}
763
- activated. remove ( "default" ) ;
764
- activated. sort ( ) ;
765
- let mut deactivated = dep
766
- . available_features
767
- . keys ( )
768
- . filter ( |f| !activated. contains ( f. as_str ( ) ) && * f != "default" )
769
- . collect :: < Vec < _ > > ( ) ;
770
- deactivated. sort ( ) ;
782
+ let ( activated, deactivated) = dep. features ( ) ;
771
783
if !activated. is_empty ( ) || !deactivated. is_empty ( ) {
772
784
let prefix = format ! ( "{:>13}" , " " ) ;
773
785
let suffix = if let Some ( version) = & dep. available_version {
0 commit comments