-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1281 from YBoy-git/will_features
READY : (willbe) : willbe .features
- Loading branch information
Showing
20 changed files
with
458 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
mod private | ||
{ | ||
use crate::*; | ||
|
||
use std:: | ||
{ | ||
collections::{ BTreeMap, HashMap }, | ||
fmt | ||
}; | ||
|
||
use _path::AbsolutePath; | ||
use former::Former; | ||
use error_tools::{ for_app::Context, Result }; | ||
use workspace::Workspace; | ||
|
||
/// Options available for the .features command | ||
#[ derive( Debug, Former ) ] | ||
pub struct FeaturesOptions | ||
{ | ||
manifest_dir : AbsolutePath, | ||
with_features_deps : bool, | ||
} | ||
|
||
/// Represents a report about features available in the package | ||
#[ derive( Debug, Default ) ] | ||
pub struct FeaturesReport | ||
{ | ||
/// Flag to turn off/on displaying feature dependencies - "feature: [deps...]" | ||
pub with_features_deps : bool, | ||
|
||
/// A key-value pair structure representing available features. | ||
/// | ||
/// Key: name of the package (useful for workspaces, where multiple packages can be found). | ||
/// | ||
/// Value: Another key-value pair representing a feature and its dependencies | ||
pub inner : HashMap< String, BTreeMap< String, Vec< String > > >, | ||
} | ||
|
||
impl fmt::Display for FeaturesReport | ||
{ | ||
fn fmt( &self, f : &mut fmt::Formatter< '_ >) -> Result< (), fmt::Error > | ||
{ | ||
self.inner.iter().try_for_each | ||
( | ( package, features ) | | ||
{ | ||
writeln!(f, "Package {}:", package)?; | ||
features.iter().try_for_each | ||
( | ( feature, dependencies ) | | ||
{ | ||
let feature = match self.with_features_deps | ||
{ | ||
false => format!( "\t{feature}" ), | ||
true | ||
=> | ||
{ | ||
let deps = dependencies.join( ", " ); | ||
format!( "\t{feature}: [{deps}]" ) | ||
} | ||
}; | ||
writeln!( f, "{feature}" ) | ||
} | ||
) | ||
} | ||
) | ||
} | ||
} | ||
|
||
/// List features | ||
pub fn features( FeaturesOptions { manifest_dir, with_features_deps } : FeaturesOptions ) -> Result< FeaturesReport > | ||
{ | ||
let workspace = Workspace::with_crate_dir( CrateDir::try_from( manifest_dir.clone() )? ).context( "Failed to find workspace" )?; | ||
let packages = workspace.packages()?.into_iter().filter | ||
( | package | | ||
package.manifest_path().as_str().starts_with( manifest_dir.as_ref().as_os_str().to_str().unwrap() ) | ||
).collect::< Vec< _ > >(); | ||
let mut report = FeaturesReport | ||
{ | ||
with_features_deps, | ||
..Default::default() | ||
}; | ||
packages.iter().for_each | ||
( | package | | ||
{ | ||
let features = package.features(); | ||
report.inner.insert(package.name().to_owned(), features.to_owned()); | ||
} | ||
); | ||
Ok( report ) | ||
} | ||
} | ||
|
||
crate::mod_interface! | ||
{ | ||
orphan use features; | ||
orphan use FeaturesOptions; | ||
orphan use FeaturesReport; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
mod private | ||
{ | ||
use crate::*; | ||
|
||
use action::features::FeaturesOptions; | ||
use std::path::PathBuf; | ||
use _path::AbsolutePath; | ||
use wca::VerifiedCommand; | ||
use wtools::error::Result; | ||
|
||
/// | ||
/// List features of a package. | ||
/// | ||
pub fn features( o : VerifiedCommand ) -> Result< () > | ||
{ | ||
let path : PathBuf = o.args.get_owned( 0 ).unwrap_or_else( || "./".into() ); | ||
let path = AbsolutePath::try_from( path )?; | ||
let with_features_deps = o.props.get_owned( "with_features_deps" ).unwrap_or( false ); | ||
let options = FeaturesOptions::former() | ||
.manifest_dir( path ) | ||
.with_features_deps( with_features_deps ) | ||
.form(); | ||
let report = action::features( options ); | ||
match report | ||
{ | ||
Ok(success) => println!("{success}"), | ||
Err(failure) => eprintln!("{failure}"), | ||
} | ||
Ok( () ) | ||
} | ||
|
||
} | ||
|
||
crate::mod_interface! | ||
{ | ||
/// List features. | ||
orphan use features; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ mod private | |
|
||
estimate | ||
} | ||
|
||
} | ||
|
||
crate::mod_interface! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,6 @@ mod private | |
{ | ||
&self.inner.features | ||
} | ||
|
||
} | ||
|
||
/// A dependency of the main crate | ||
|
8 changes: 8 additions & 0 deletions
8
module/move/willbe/tests/asset/three_packages_with_features/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"*", | ||
] | ||
|
||
[workspace.metadata] | ||
discord_url = "https://discord.gg/123456789" |
17 changes: 17 additions & 0 deletions
17
module/move/willbe/tests/asset/three_packages_with_features/b/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "_chain_of_packages_b" | ||
version = "0.1.0" | ||
edition = "2021" | ||
repository = "https://github.com/Username/test/b" | ||
|
||
[package.metadata] | ||
stability = "stable" | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
_chain_of_packages_c = { path = "../c", optional = true } | ||
|
||
[features] | ||
enabled = [] | ||
default = ["boo"] | ||
boo = ["_chain_of_packages_c"] |
2 changes: 2 additions & 0 deletions
2
module/move/willbe/tests/asset/three_packages_with_features/b/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!--{ generate.module_header.start() }--> | ||
<!--{ generate.module_header.end }--> |
17 changes: 17 additions & 0 deletions
17
module/move/willbe/tests/asset/three_packages_with_features/b/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pub fn add( left : usize, right : usize ) -> usize | ||
{ | ||
left + right | ||
} | ||
|
||
#[ cfg( test ) ] | ||
mod tests | ||
{ | ||
use super::*; | ||
|
||
#[ test ] | ||
fn it_works() | ||
{ | ||
let result = add( 2, 2 ); | ||
assert_eq!( result, 4 ); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
module/move/willbe/tests/asset/three_packages_with_features/c/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "_chain_of_packages_c" | ||
version = "0.1.0" | ||
edition = "2021" | ||
repository = "https://github.com/Username/test/c" | ||
|
||
[package.metadata] | ||
discord_url = "https://discord.gg/m3YfbXpUUY" | ||
stability = "stable" | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[features] | ||
enabled = [] | ||
default = ["foo"] | ||
foo = [] |
2 changes: 2 additions & 0 deletions
2
module/move/willbe/tests/asset/three_packages_with_features/c/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!--{ generate.module_header.start() }--> | ||
<!--{ generate.module_header.end }--> |
17 changes: 17 additions & 0 deletions
17
module/move/willbe/tests/asset/three_packages_with_features/c/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pub fn add( left : usize, right : usize ) -> usize | ||
{ | ||
left + right | ||
} | ||
|
||
#[ cfg( test ) ] | ||
mod tests | ||
{ | ||
use super::*; | ||
|
||
#[ test ] | ||
fn it_works() | ||
{ | ||
let result = add( 2, 2 ); | ||
assert_eq!( result, 4 ); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
module/move/willbe/tests/asset/three_packages_with_features/d/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "_chain_of_packages_d" | ||
version = "0.1.0" | ||
edition = "2021" | ||
repository = "https://github.com/Username/test/c" | ||
|
||
[package.metadata] | ||
stability = "stable" | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[features] | ||
enabled = [] |
2 changes: 2 additions & 0 deletions
2
module/move/willbe/tests/asset/three_packages_with_features/d/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!--{ generate.module_header.start() }--> | ||
<!--{ generate.module_header.end }--> |
17 changes: 17 additions & 0 deletions
17
module/move/willbe/tests/asset/three_packages_with_features/d/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pub fn add( left : usize, right : usize ) -> usize | ||
{ | ||
left + right | ||
} | ||
|
||
#[ cfg( test ) ] | ||
mod tests | ||
{ | ||
use super::*; | ||
|
||
#[ test ] | ||
fn it_works() | ||
{ | ||
let result = add( 2, 2 ); | ||
assert_eq!( result, 4 ); | ||
} | ||
} |
Oops, something went wrong.