aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/show_command.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/command/show_command.rs')
-rw-r--r--crates/shirabe/src/command/show_command.rs163
1 files changed, 84 insertions, 79 deletions
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index 06abec4..27bda55 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -85,25 +85,25 @@ impl ShowCommand {
output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
) -> anyhow::Result<i64> {
self.version_parser = VersionParser::new();
- if input.borrow().get_option("tree").as_bool() == Some(true) {
+ if input.borrow().get_option("tree")?.as_bool() == Some(true) {
self.init_styles(output.clone());
}
let mut composer = self.try_composer(None, None);
- if input.borrow().get_option("installed").as_bool() == Some(true)
- && input.borrow().get_option("self").as_bool() != Some(true)
+ if input.borrow().get_option("installed")?.as_bool() == Some(true)
+ && input.borrow().get_option("self")?.as_bool() != Some(true)
{
self.get_io().write_error("<warning>You are using the deprecated option \"installed\". Only installed packages are shown by default now. The --all option can be used to show all packages.</warning>");
}
- if input.borrow().get_option("outdated").as_bool() == Some(true) {
+ if input.borrow().get_option("outdated")?.as_bool() == Some(true) {
input
.borrow_mut()
.set_option("latest", PhpMixed::Bool(true));
} else if input
.borrow()
- .get_option("ignore")
+ .get_option("ignore")?
.as_list()
.map_or(0, |l| l.len())
> 0
@@ -111,19 +111,19 @@ impl ShowCommand {
self.get_io().write_error("<warning>You are using the option \"ignore\" for action other than \"outdated\", it will be ignored.</warning>");
}
- if input.borrow().get_option("direct").as_bool() == Some(true)
- && (input.borrow().get_option("all").as_bool() == Some(true)
- || input.borrow().get_option("available").as_bool() == Some(true)
- || input.borrow().get_option("platform").as_bool() == Some(true))
+ if input.borrow().get_option("direct")?.as_bool() == Some(true)
+ && (input.borrow().get_option("all")?.as_bool() == Some(true)
+ || input.borrow().get_option("available")?.as_bool() == Some(true)
+ || input.borrow().get_option("platform")?.as_bool() == Some(true))
{
self.get_io().write_error("The --direct (-D) option is not usable in combination with --all, --platform (-p) or --available (-a)");
return Ok(1);
}
- if input.borrow().get_option("tree").as_bool() == Some(true)
- && (input.borrow().get_option("all").as_bool() == Some(true)
- || input.borrow().get_option("available").as_bool() == Some(true))
+ if input.borrow().get_option("tree")?.as_bool() == Some(true)
+ && (input.borrow().get_option("all")?.as_bool() == Some(true)
+ || input.borrow().get_option("available")?.as_bool() == Some(true))
{
self.get_io().write_error("The --tree (-t) option is not usable in combination with --all or --available (-a)");
@@ -131,9 +131,9 @@ impl ShowCommand {
}
let only_count: usize = [
- input.borrow().get_option("patch-only").as_bool() == Some(true),
- input.borrow().get_option("minor-only").as_bool() == Some(true),
- input.borrow().get_option("major-only").as_bool() == Some(true),
+ input.borrow().get_option("patch-only")?.as_bool() == Some(true),
+ input.borrow().get_option("minor-only")?.as_bool() == Some(true),
+ input.borrow().get_option("major-only")?.as_bool() == Some(true),
]
.iter()
.filter(|b| **b)
@@ -146,8 +146,8 @@ impl ShowCommand {
return Ok(1);
}
- if input.borrow().get_option("tree").as_bool() == Some(true)
- && input.borrow().get_option("latest").as_bool() == Some(true)
+ if input.borrow().get_option("tree")?.as_bool() == Some(true)
+ && input.borrow().get_option("latest")?.as_bool() == Some(true)
{
self.get_io().write_error(
"The --tree (-t) option is not usable in combination with --latest (-l)",
@@ -156,8 +156,8 @@ impl ShowCommand {
return Ok(1);
}
- if input.borrow().get_option("tree").as_bool() == Some(true)
- && input.borrow().get_option("path").as_bool() == Some(true)
+ if input.borrow().get_option("tree")?.as_bool() == Some(true)
+ && input.borrow().get_option("path")?.as_bool() == Some(true)
{
self.get_io().write_error(
"The --tree (-t) option is not usable in combination with --path (-P)",
@@ -168,7 +168,7 @@ impl ShowCommand {
let format = input
.borrow()
- .get_option("format")
+ .get_option("format")?
.as_string()
.unwrap_or("text")
.to_string();
@@ -214,20 +214,25 @@ impl ShowCommand {
let installed_repo: RepositoryInterfaceHandle;
let repos: RepositoryInterfaceHandle;
- if input.borrow().get_option("self").as_bool() == Some(true)
- && input.borrow().get_option("installed").as_bool() != Some(true)
- && input.borrow().get_option("locked").as_bool() != Some(true)
+ if input.borrow().get_option("self")?.as_bool() == Some(true)
+ && input.borrow().get_option("installed")?.as_bool() != Some(true)
+ && input.borrow().get_option("locked")?.as_bool() != Some(true)
{
let composer = self.require_composer(None, None)?;
let package = crate::package::RootPackageInterfaceHandle::dup(
composer.borrow_partial().get_package(),
);
- if input.borrow().get_option("name-only").as_bool() == Some(true) {
+ if input.borrow().get_option("name-only")?.as_bool() == Some(true) {
self.get_io().write(&package.get_name());
return Ok(0);
}
- if input.borrow().get_argument("package").as_string().is_some() {
+ if input
+ .borrow()
+ .get_argument("package")?
+ .as_string()
+ .is_some()
+ {
return Err(InvalidArgumentException {
message: "You cannot use --self together with a package name".to_string(),
code: 0,
@@ -241,14 +246,14 @@ impl ShowCommand {
RepositoryInterfaceHandle::new(RootPackageRepository::new(package.clone())),
]));
single_package = Some(package.clone().into());
- } else if input.borrow().get_option("platform").as_bool() == Some(true) {
+ } else if input.borrow().get_option("platform")?.as_bool() == Some(true) {
installed_repo = RepositoryInterfaceHandle::new(InstalledRepository::new(vec![
platform_repo.clone().into(),
]));
repos = RepositoryInterfaceHandle::new(InstalledRepository::new(vec![
platform_repo.clone().into(),
]));
- } else if input.borrow().get_option("available").as_bool() == Some(true) {
+ } else if input.borrow().get_option("available")?.as_bool() == Some(true) {
let mut ir = InstalledRepository::new(vec![platform_repo.clone().into()]);
if let Some(ref composer) = composer {
let composer = crate::command::composer_full(composer);
@@ -281,7 +286,7 @@ impl ShowCommand {
));
installed_repo = RepositoryInterfaceHandle::new(ir);
}
- } else if input.borrow().get_option("all").as_bool() == Some(true) && composer.is_some() {
+ } else if input.borrow().get_option("all")?.as_bool() == Some(true) && composer.is_some() {
let mut composer_ref = crate::command::composer_full_mut(composer.as_ref().unwrap());
let local_repo = composer_ref
.get_repository_manager()
@@ -321,7 +326,7 @@ impl ShowCommand {
composite_input.push(r.clone());
}
repos = RepositoryInterfaceHandle::new(CompositeRepository::new(composite_input));
- } else if input.borrow().get_option("all").as_bool() == Some(true) {
+ } else if input.borrow().get_option("all")?.as_bool() == Some(true) {
let default_repos =
RepositoryFactory::default_repos_with_default_manager(self.get_io())?;
let names: Vec<String> = default_repos.keys().cloned().collect();
@@ -337,7 +342,7 @@ impl ShowCommand {
composite_input.push(v);
}
repos = RepositoryInterfaceHandle::new(CompositeRepository::new(composite_input));
- } else if input.borrow().get_option("locked").as_bool() == Some(true) {
+ } else if input.borrow().get_option("locked")?.as_bool() == Some(true) {
if composer.is_none()
|| !crate::command::composer_full_mut(composer.as_ref().unwrap())
.get_locker()
@@ -354,9 +359,9 @@ impl ShowCommand {
let locker_rc = composer_ref.get_locker().clone();
let mut locker = locker_rc.borrow_mut();
let lr = locker.get_locked_repository(
- input.borrow().get_option("no-dev").as_bool() != Some(true),
+ input.borrow().get_option("no-dev")?.as_bool() != Some(true),
)?;
- if input.borrow().get_option("self").as_bool() == Some(true) {
+ if input.borrow().get_option("self")?.as_bool() == Some(true) {
lr.add_package(
crate::package::RootPackageInterfaceHandle::dup(composer_ref.get_package())
.into(),
@@ -386,7 +391,7 @@ impl ShowCommand {
let root_pkg = composer_local.get_package();
let root_repo: RepositoryInterfaceHandle =
- if input.borrow().get_option("self").as_bool() == Some(true) {
+ if input.borrow().get_option("self")?.as_bool() == Some(true) {
RepositoryInterfaceHandle::new(RootPackageRepository::new(
crate::package::RootPackageInterfaceHandle::dup(
composer_local.get_package(),
@@ -395,7 +400,7 @@ impl ShowCommand {
} else {
RepositoryInterfaceHandle::new(InstalledArrayRepository::new()?)
};
- if input.borrow().get_option("no-dev").as_bool() == Some(true) {
+ if input.borrow().get_option("no-dev")?.as_bool() == Some(true) {
let local_packages = composer_local
.get_repository_manager()
.borrow()
@@ -468,7 +473,7 @@ impl ShowCommand {
.dispatch(Some(&command_event_name), Some(&mut command_event))?;
}
- if input.borrow().get_option("latest").as_bool() == Some(true) && composer.is_none() {
+ if input.borrow().get_option("latest")?.as_bool() == Some(true) && composer.is_none() {
self.get_io().write_error(
"No composer.json found in the current directory, disabling \"latest\" option",
);
@@ -479,7 +484,7 @@ impl ShowCommand {
let package_filter: Option<String> = input
.borrow()
- .get_argument("package")
+ .get_argument("package")?
.as_string()
.map(|s| s.to_string());
@@ -492,11 +497,11 @@ impl ShowCommand {
&*installed_repo.borrow(),
&repos,
pf,
- input.borrow().get_argument("version"),
+ input.borrow().get_argument("version")?,
)?;
if let Some(ref pkg) = matched_package {
- if input.borrow().get_option("direct").as_bool() == Some(true) {
+ if input.borrow().get_option("direct")?.as_bool() == Some(true) {
if !in_array(
PhpMixed::String(pkg.get_name()),
&PhpMixed::List(
@@ -522,7 +527,7 @@ impl ShowCommand {
if matched_package.is_none() {
let options = input.borrow().get_options();
let mut hint = String::new();
- if input.borrow().get_option("locked").as_bool() == Some(true) {
+ if input.borrow().get_option("locked")?.as_bool() == Some(true) {
hint.push_str(" in lock file");
}
if options.contains_key("working-dir") {
@@ -535,12 +540,12 @@ impl ShowCommand {
));
}
if PlatformRepository::is_platform_package(pf)
- && input.borrow().get_option("platform").as_bool() != Some(true)
+ && input.borrow().get_option("platform")?.as_bool() != Some(true)
{
hint.push_str(", try using --platform (-p) to show platform packages");
}
- if input.borrow().get_option("all").as_bool() != Some(true)
- && input.borrow().get_option("available").as_bool() != Some(true)
+ if input.borrow().get_option("all")?.as_bool() != Some(true)
+ && input.borrow().get_option("available")?.as_bool() != Some(true)
{
hint.push_str(
", try using --available (-a) to show all available packages",
@@ -562,7 +567,7 @@ impl ShowCommand {
// assert(isset($versions));
let mut exit_code: i64 = 0;
- if input.borrow().get_option("tree").as_bool() == Some(true) {
+ if input.borrow().get_option("tree")?.as_bool() == Some(true) {
let array_tree = self.generate_package_tree(
package.clone().into(),
&*installed_repo.borrow(),
@@ -591,31 +596,31 @@ impl ShowCommand {
}
let mut latest_package: Option<crate::package::PackageInterfaceHandle> = None;
- if input.borrow().get_option("latest").as_bool() == Some(true) {
+ if input.borrow().get_option("latest")?.as_bool() == Some(true) {
latest_package = self.find_latest_package(
package.clone().into(),
composer.as_ref().unwrap(),
&platform_repo,
input
.borrow()
- .get_option("major-only")
+ .get_option("major-only")?
.as_bool()
.unwrap_or(false),
input
.borrow()
- .get_option("minor-only")
+ .get_option("minor-only")?
.as_bool()
.unwrap_or(false),
input
.borrow()
- .get_option("patch-only")
+ .get_option("patch-only")?
.as_bool()
.unwrap_or(false),
platform_req_filter.clone(),
)?;
}
- if input.borrow().get_option("outdated").as_bool() == Some(true)
- && input.borrow().get_option("strict").as_bool() == Some(true)
+ if input.borrow().get_option("outdated")?.as_bool() == Some(true)
+ && input.borrow().get_option("strict")?.as_bool() == Some(true)
&& latest_package.is_some()
&& latest_package
.as_ref()
@@ -631,7 +636,7 @@ impl ShowCommand {
{
exit_code = 1;
}
- if input.borrow().get_option("path").as_bool() == Some(true) {
+ if input.borrow().get_option("path")?.as_bool() == Some(true) {
self.get_io().write_no_newline(&package.get_name());
let path = {
let composer_ref = composer.as_ref().unwrap();
@@ -672,7 +677,7 @@ impl ShowCommand {
}
// show tree view if requested
- if input.borrow().get_option("tree").as_bool() == Some(true) {
+ if input.borrow().get_option("tree")?.as_bool() == Some(true) {
let root_requires = self.get_root_requires();
let mut packages = installed_repo.get_packages()?;
packages.sort_by(|a, b| {
@@ -734,11 +739,11 @@ impl ShowCommand {
}
let mut package_list_filter: Option<Vec<String>> = None;
- if input.borrow().get_option("direct").as_bool() == Some(true) {
+ if input.borrow().get_option("direct")?.as_bool() == Some(true) {
package_list_filter = Some(self.get_root_requires());
}
- if input.borrow().get_option("path").as_bool() == Some(true) && composer.is_none() {
+ if input.borrow().get_option("path")?.as_bool() == Some(true) && composer.is_none() {
self.get_io().write_error(
"No composer.json found in the current directory, disabling \"path\" option",
);
@@ -831,15 +836,15 @@ impl ShowCommand {
}
}
- let show_all_types = input.borrow().get_option("all").as_bool() == Some(true);
- let show_latest = input.borrow().get_option("latest").as_bool() == Some(true);
- let show_major_only = input.borrow().get_option("major-only").as_bool() == Some(true);
- let show_minor_only = input.borrow().get_option("minor-only").as_bool() == Some(true);
- let show_patch_only = input.borrow().get_option("patch-only").as_bool() == Some(true);
+ let show_all_types = input.borrow().get_option("all")?.as_bool() == Some(true);
+ let show_latest = input.borrow().get_option("latest")?.as_bool() == Some(true);
+ let show_major_only = input.borrow().get_option("major-only")?.as_bool() == Some(true);
+ let show_minor_only = input.borrow().get_option("minor-only")?.as_bool() == Some(true);
+ let show_patch_only = input.borrow().get_option("patch-only")?.as_bool() == Some(true);
let ignored_packages_regex = base_package::package_names_to_regexp(
&input
.borrow()
- .get_option("ignore")
+ .get_option("ignore")?
.as_list()
.map(|l| {
l.iter()
@@ -898,21 +903,21 @@ impl ShowCommand {
}
}
- let write_path = input.borrow().get_option("name-only").as_bool() != Some(true)
- && input.borrow().get_option("path").as_bool() == Some(true);
- write_version = input.borrow().get_option("name-only").as_bool() != Some(true)
- && input.borrow().get_option("path").as_bool() != Some(true)
+ let write_path = input.borrow().get_option("name-only")?.as_bool() != Some(true)
+ && input.borrow().get_option("path")?.as_bool() == Some(true);
+ write_version = input.borrow().get_option("name-only")?.as_bool() != Some(true)
+ && input.borrow().get_option("path")?.as_bool() != Some(true)
&& *show_version;
let write_latest = write_version && show_latest;
- write_description = input.borrow().get_option("name-only").as_bool() != Some(true)
- && input.borrow().get_option("path").as_bool() != Some(true);
+ write_description = input.borrow().get_option("name-only")?.as_bool() != Some(true)
+ && input.borrow().get_option("path")?.as_bool() != Some(true);
let write_release_date = write_latest
- && (input.borrow().get_option("sort-by-age").as_bool() == Some(true)
+ && (input.borrow().get_option("sort-by-age")?.as_bool() == Some(true)
|| format == "json");
let mut has_outdated_packages = false;
- if input.borrow().get_option("sort-by-age").as_bool() == Some(true) {
+ if input.borrow().get_option("sort-by-age")?.as_bool() == Some(true) {
type_packages.sort_by(|_ka, a, _kb, b| match (a, b) {
(PackageOrName::Pkg(a), PackageOrName::Pkg(b)) => {
a.get_release_date().cmp(&b.get_release_date())
@@ -950,14 +955,14 @@ impl ShowCommand {
package_is_up_to_date || (latest_package.is_none() && show_major_only);
let package_is_ignored =
Preg::is_match(&ignored_packages_regex, &package.get_pretty_name())?;
- if input.borrow().get_option("outdated").as_bool() == Some(true)
+ if input.borrow().get_option("outdated")?.as_bool() == Some(true)
&& (package_is_up_to_date || package_is_ignored)
{
continue;
}
- if input.borrow().get_option("outdated").as_bool() == Some(true)
- || input.borrow().get_option("strict").as_bool() == Some(true)
+ if input.borrow().get_option("outdated")?.as_bool() == Some(true)
+ || input.borrow().get_option("strict")?.as_bool() == Some(true)
{
has_outdated_packages = true;
}
@@ -980,7 +985,7 @@ impl ShowCommand {
)),
);
if format != "json"
- || input.borrow().get_option("name-only").as_bool() != Some(true)
+ || input.borrow().get_option("name-only")?.as_bool() != Some(true)
{
package_view_data.insert(
"homepage".to_string(),
@@ -1159,7 +1164,7 @@ impl ShowCommand {
write_release_date,
},
);
- if input.borrow().get_option("strict").as_bool() == Some(true)
+ if input.borrow().get_option("strict")?.as_bool() == Some(true)
&& has_outdated_packages
{
exit_code = 1;
@@ -1194,7 +1199,7 @@ impl ShowCommand {
.collect(),
)));
} else {
- if input.borrow().get_option("latest").as_bool() == Some(true)
+ if input.borrow().get_option("latest")?.as_bool() == Some(true)
&& view_data.values().any(|v| !v.is_empty())
{
let io = self.get_io();
@@ -1202,7 +1207,7 @@ impl ShowCommand {
io.write_error("Legend:");
io.write_error("! patch or minor release available - update recommended");
io.write_error("~ major release available - update possible");
- if input.borrow().get_option("outdated").as_bool() != Some(true) {
+ if input.borrow().get_option("outdated")?.as_bool() != Some(true) {
io.write_error("= up to date version");
}
} else {
@@ -1211,7 +1216,7 @@ impl ShowCommand {
io.write_error(
"- <comment>major</comment> release available - update possible",
);
- if input.borrow().get_option("outdated").as_bool() != Some(true) {
+ if input.borrow().get_option("outdated")?.as_bool() != Some(true) {
io.write_error("- <info>up to date</info> version");
}
}
@@ -1254,7 +1259,7 @@ impl ShowCommand {
}
}
- if write_latest && input.borrow().get_option("direct").as_bool() != Some(true) {
+ if write_latest && input.borrow().get_option("direct")?.as_bool() != Some(true) {
let mut direct_deps: Vec<IndexMap<String, PhpMixed>> = Vec::new();
let mut transitive_deps: Vec<IndexMap<String, PhpMixed>> = Vec::new();
for pkg in packages.iter() {
@@ -1387,7 +1392,7 @@ impl ShowCommand {
io.write_no_newline(&format!(
"{}<href={}>{}</>{}",
indent,
- OutputFormatter::escape(&link),
+ OutputFormatter::escape(&link).expect("OutputFormatter::escape failed"),
name,
" ".repeat(pad)
));
@@ -2264,12 +2269,12 @@ impl ShowCommand {
];
for color in self.colors.iter() {
- let style = OutputFormatterStyle::new(Some(color.as_str()), None, None);
+ let style = OutputFormatterStyle::new(Some(color.as_str()), None, vec![]);
output
.borrow()
.get_formatter()
.borrow_mut()
- .set_style(color, style);
+ .set_style(color, Box::new(style));
}
}