Skip to content

Commit

Permalink
Add options to include versions and paths in package listing
Browse files Browse the repository at this point in the history
Introduced "with_version" and "with_path" options to the package listing command, allowing users to optionally include the versions and paths of the listed packages. Also refactored the code to use a ListProperties struct for better organization and readability. The new options default to false.
  • Loading branch information
Barsik-sus committed Feb 13, 2024
1 parent 00ff4cd commit c902e2c
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 207 deletions.
64 changes: 54 additions & 10 deletions module/move/willbe/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ mod private

use path::AbsolutePath;
use endpoint::{ list as l, list::{ ListFormat, ListArgs } };
use former::Former;

#[ derive( Former ) ]
struct ListProperties
{
#[ default( ListFormat::Tree ) ]
format : ListFormat,

#[ default( false ) ]
with_version : bool,
#[ default( false ) ]
with_path : bool,

#[ default( true ) ]
with_local : bool,
#[ default( false ) ]
with_remote : bool,

#[ default( true ) ]
with_primary : bool,
#[ default( false ) ]
with_dev : bool,
#[ default( false ) ]
with_build : bool,
}

///
/// List workspace packages.
Expand All @@ -27,17 +52,14 @@ mod private
let path_to_workspace : PathBuf = args.get_owned( 0 ).unwrap_or( std::env::current_dir().context( "Workspace list command without subject" )? );
let path_to_workspace = AbsolutePath::try_from( path_to_workspace )?;

let format = properties.get_owned( "format" ).map( ListFormat::from_str ).transpose()?.unwrap_or_default();

let with_local = properties.get_owned( "with_local" ).unwrap_or( true );
let with_remote = properties.get_owned( "with_remote" ).unwrap_or( false );

let with_primary = properties.get_owned( "with_primary" ).unwrap_or( true );
let with_dev = properties.get_owned( "with_dev" ).unwrap_or( false );
let with_build = properties.get_owned( "with_build" ).unwrap_or( false );
let ListProperties { format, with_version, with_path, with_local, with_remote, with_primary, with_dev, with_build } = ListProperties::try_from( properties )?;

let crate_dir = CrateDir::try_from( path_to_workspace )?;

let mut additional_info = HashSet::new();
if with_version { additional_info.insert( l::PackageAdditionalInfo::Version ); }
if with_path { additional_info.insert( l::PackageAdditionalInfo::Path ); }

let mut sources = HashSet::new();
if with_local { sources.insert( l::DependencySource::Local ); }
if with_remote { sources.insert( l::DependencySource::Remote ); }
Expand All @@ -50,13 +72,14 @@ mod private
let args = ListArgs::former()
.path_to_manifest( crate_dir )
.format( format )
.info( additional_info )
.dependency_sources( sources )
.dependency_categories( categories )
.form();

match endpoint::listv2( args )
match endpoint::list( args )
{
core::result::Result::Ok( report ) =>
Ok( report ) =>
{
println!( "{report}" );
}
Expand All @@ -70,6 +93,27 @@ mod private

Ok( () )
}

impl TryFrom< Props > for ListProperties
{
type Error = wtools::error::for_app::Error;
fn try_from( value : Props ) -> Result< Self, Self::Error >
{
let mut this = Self::former();

this = if let Some( v ) = value.get_owned( "format" ).map( ListFormat::from_str ) { this.format( v? ) } else { this };
this = if let Some( v ) = value.get_owned( "with_version" ) { this.with_version::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_path" ) { this.with_path::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_local" ) { this.with_local::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_remote" ) { this.with_remote::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_primary" ) { this.with_primary::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_dev" ) { this.with_dev::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "with_build" ) { this.with_build::< bool >( v ) } else { this };

Ok( this.form() )
}
}

}

//
Expand Down
2 changes: 2 additions & 0 deletions module/move/willbe/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub( crate ) mod private
.phrase( "list" )
.subject( "The command will generate a list of packages based on a path that must containing a `Cargo.toml` file. If no path is provided, the current directory is used.", Type::Path, true )
.property( "format", "Adjusts the output format - 'topsort' for a topologically sorted list or 'tree' for a structure of independent crates trees. The default is `tree`.", Type::String, true )
.property( "with_version", "`true` to include the versions of the packages in the output. Defaults to `false`.", Type::Bool, true )
.property( "with_path", "`true` to include the paths of the packages in the output. Defaults to `false`.", Type::Bool, true )
.property( "with_primary", "`true` to include primary packages in the output, `false` otherwise. Defaults to `true`.", Type::Bool, true )
.property( "with_dev", "`true` to include development packages in the output, `false` otherwise. Defaults to `false`.", Type::Bool, true )
.property( "with_build", "`true` to include build packages in the output, `false` otherwise. Defaults to `false`.", Type::Bool, true )
Expand Down
Loading

0 comments on commit c902e2c

Please sign in to comment.