mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-04-06 20:00:53 +01:00
parent
f0e69a08e2
commit
6ae16a7dac
7 changed files with 152 additions and 16 deletions
|
@ -4,9 +4,11 @@ use anyhow::Context;
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use semver::VersionReq;
|
use semver::VersionReq;
|
||||||
|
|
||||||
use crate::cli::{config::read_config, AnyPackageIdentifier, VersionedPackageName};
|
use crate::cli::{
|
||||||
|
config::read_config, dep_type_to_key, AnyPackageIdentifier, VersionedPackageName,
|
||||||
|
};
|
||||||
use pesde::{
|
use pesde::{
|
||||||
manifest::{target::TargetKind, Alias},
|
manifest::{target::TargetKind, Alias, DependencyType},
|
||||||
names::PackageNames,
|
names::PackageNames,
|
||||||
source::{
|
source::{
|
||||||
git::{specifier::GitDependencySpecifier, GitPackageSource},
|
git::{specifier::GitDependencySpecifier, GitPackageSource},
|
||||||
|
@ -167,13 +169,13 @@ impl AddCommand {
|
||||||
.context("failed to read manifest")?,
|
.context("failed to read manifest")?,
|
||||||
)
|
)
|
||||||
.context("failed to parse manifest")?;
|
.context("failed to parse manifest")?;
|
||||||
let dependency_key = if self.peer {
|
let dependency_key = dep_type_to_key(if self.peer {
|
||||||
"peer_dependencies"
|
DependencyType::Peer
|
||||||
} else if self.dev {
|
} else if self.dev {
|
||||||
"dev_dependencies"
|
DependencyType::Dev
|
||||||
} else {
|
} else {
|
||||||
"dependencies"
|
DependencyType::Standard
|
||||||
};
|
});
|
||||||
|
|
||||||
let alias = match self.alias {
|
let alias = match self.alias {
|
||||||
Some(alias) => alias,
|
Some(alias) => alias,
|
||||||
|
|
51
src/cli/commands/list.rs
Normal file
51
src/cli/commands/list.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
|
use clap::Args;
|
||||||
|
|
||||||
|
use crate::cli::{
|
||||||
|
dep_type_to_key,
|
||||||
|
style::{INFO_STYLE, SUCCESS_STYLE},
|
||||||
|
};
|
||||||
|
use pesde::{
|
||||||
|
manifest::{Alias, DependencyType},
|
||||||
|
source::specifiers::DependencySpecifiers,
|
||||||
|
Project,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
pub struct ListCommand {}
|
||||||
|
|
||||||
|
impl ListCommand {
|
||||||
|
pub async fn run(self, project: Project) -> anyhow::Result<()> {
|
||||||
|
let manifest = project
|
||||||
|
.deser_manifest()
|
||||||
|
.await
|
||||||
|
.context("failed to read manifest")?;
|
||||||
|
|
||||||
|
let all_deps = manifest
|
||||||
|
.all_dependencies()
|
||||||
|
.context("failed to get all dependencies")?
|
||||||
|
.into_iter()
|
||||||
|
.fold(
|
||||||
|
BTreeMap::<DependencyType, BTreeMap<Alias, DependencySpecifiers>>::new(),
|
||||||
|
|mut acc, (alias, (spec, ty))| {
|
||||||
|
acc.entry(ty).or_default().insert(alias, spec);
|
||||||
|
acc
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
for (dep_ty, deps) in all_deps {
|
||||||
|
let dep_key = dep_type_to_key(dep_ty);
|
||||||
|
println!("{}", INFO_STYLE.apply_to(dep_key));
|
||||||
|
|
||||||
|
for (alias, spec) in deps {
|
||||||
|
println!("{}: {spec}", SUCCESS_STYLE.apply_to(alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,12 +8,14 @@ mod deprecate;
|
||||||
mod execute;
|
mod execute;
|
||||||
mod init;
|
mod init;
|
||||||
mod install;
|
mod install;
|
||||||
|
mod list;
|
||||||
mod outdated;
|
mod outdated;
|
||||||
#[cfg(feature = "patches")]
|
#[cfg(feature = "patches")]
|
||||||
mod patch;
|
mod patch;
|
||||||
#[cfg(feature = "patches")]
|
#[cfg(feature = "patches")]
|
||||||
mod patch_commit;
|
mod patch_commit;
|
||||||
mod publish;
|
mod publish;
|
||||||
|
mod remove;
|
||||||
mod run;
|
mod run;
|
||||||
#[cfg(feature = "version-management")]
|
#[cfg(feature = "version-management")]
|
||||||
mod self_install;
|
mod self_install;
|
||||||
|
@ -41,6 +43,9 @@ pub enum Subcommand {
|
||||||
/// Adds a dependency to the project
|
/// Adds a dependency to the project
|
||||||
Add(add::AddCommand),
|
Add(add::AddCommand),
|
||||||
|
|
||||||
|
/// Removes a dependency from the project
|
||||||
|
Remove(remove::RemoveCommand),
|
||||||
|
|
||||||
/// Installs all dependencies for the project
|
/// Installs all dependencies for the project
|
||||||
Install(install::InstallCommand),
|
Install(install::InstallCommand),
|
||||||
|
|
||||||
|
@ -50,6 +55,9 @@ pub enum Subcommand {
|
||||||
/// Checks for outdated dependencies
|
/// Checks for outdated dependencies
|
||||||
Outdated(outdated::OutdatedCommand),
|
Outdated(outdated::OutdatedCommand),
|
||||||
|
|
||||||
|
/// Lists all dependencies in the project
|
||||||
|
List(list::ListCommand),
|
||||||
|
|
||||||
/// Runs a script, an executable package, or a file with Lune
|
/// Runs a script, an executable package, or a file with Lune
|
||||||
Run(run::RunCommand),
|
Run(run::RunCommand),
|
||||||
|
|
||||||
|
@ -91,9 +99,11 @@ impl Subcommand {
|
||||||
Subcommand::Cas(cas) => cas.run(project).await,
|
Subcommand::Cas(cas) => cas.run(project).await,
|
||||||
Subcommand::Init(init) => init.run(project).await,
|
Subcommand::Init(init) => init.run(project).await,
|
||||||
Subcommand::Add(add) => add.run(project).await,
|
Subcommand::Add(add) => add.run(project).await,
|
||||||
|
Subcommand::Remove(remove) => remove.run(project).await,
|
||||||
Subcommand::Install(install) => install.run(project, reqwest).await,
|
Subcommand::Install(install) => install.run(project, reqwest).await,
|
||||||
Subcommand::Update(update) => update.run(project, reqwest).await,
|
Subcommand::Update(update) => update.run(project, reqwest).await,
|
||||||
Subcommand::Outdated(outdated) => outdated.run(project).await,
|
Subcommand::Outdated(outdated) => outdated.run(project).await,
|
||||||
|
Subcommand::List(list) => list.run(project).await,
|
||||||
Subcommand::Run(run) => run.run(project).await,
|
Subcommand::Run(run) => run.run(project).await,
|
||||||
Subcommand::Publish(publish) => publish.run(project, reqwest).await,
|
Subcommand::Publish(publish) => publish.run(project, reqwest).await,
|
||||||
Subcommand::Yank(yank) => yank.run(project, reqwest).await,
|
Subcommand::Yank(yank) => yank.run(project, reqwest).await,
|
||||||
|
|
59
src/cli/commands/remove.rs
Normal file
59
src/cli/commands/remove.rs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
|
use clap::Args;
|
||||||
|
|
||||||
|
use crate::cli::{
|
||||||
|
dep_type_to_key,
|
||||||
|
style::{INFO_STYLE, SUCCESS_STYLE},
|
||||||
|
};
|
||||||
|
use pesde::{
|
||||||
|
manifest::{Alias, DependencyType},
|
||||||
|
Project,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
pub struct RemoveCommand {
|
||||||
|
/// The alias of the package to remove
|
||||||
|
#[arg(index = 1)]
|
||||||
|
alias: Alias,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RemoveCommand {
|
||||||
|
pub async fn run(self, project: Project) -> anyhow::Result<()> {
|
||||||
|
let mut manifest = toml_edit::DocumentMut::from_str(
|
||||||
|
&project
|
||||||
|
.read_manifest()
|
||||||
|
.await
|
||||||
|
.context("failed to read manifest")?,
|
||||||
|
)
|
||||||
|
.context("failed to parse manifest")?;
|
||||||
|
|
||||||
|
let Some(dep_key) = DependencyType::VARIANTS
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.map(dep_type_to_key)
|
||||||
|
.find(|dependency_key| {
|
||||||
|
manifest[dependency_key]
|
||||||
|
.as_table_mut()
|
||||||
|
.is_some_and(|table| table.remove(self.alias.as_str()).is_some())
|
||||||
|
})
|
||||||
|
else {
|
||||||
|
anyhow::bail!("package under alias `{}` not found in manifest", self.alias)
|
||||||
|
};
|
||||||
|
|
||||||
|
project
|
||||||
|
.write_manifest(manifest.to_string())
|
||||||
|
.await
|
||||||
|
.context("failed to write manifest")?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} removed {} from {}!",
|
||||||
|
SUCCESS_STYLE.apply_to("success!"),
|
||||||
|
INFO_STYLE.apply_to(self.alias),
|
||||||
|
INFO_STYLE.apply_to(dep_key)
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
use super::files::make_executable;
|
use super::files::make_executable;
|
||||||
use crate::cli::{
|
use crate::cli::{
|
||||||
bin_dir,
|
bin_dir, dep_type_to_key,
|
||||||
reporters::{self, CliReporter},
|
reporters::{self, CliReporter},
|
||||||
resolve_overrides, run_on_workspace_members,
|
resolve_overrides, run_on_workspace_members,
|
||||||
style::{ADDED_STYLE, REMOVED_STYLE, WARN_PREFIX},
|
style::{ADDED_STYLE, REMOVED_STYLE, WARN_PREFIX},
|
||||||
|
@ -550,13 +550,10 @@ pub fn print_package_diff(prefix: &str, old_graph: DependencyGraph, new_graph: D
|
||||||
|
|
||||||
for (ty, set) in dependency_groups {
|
for (ty, set) in dependency_groups {
|
||||||
println!();
|
println!();
|
||||||
|
println!(
|
||||||
let ty_name = match ty {
|
"{}",
|
||||||
DependencyType::Standard => "dependencies",
|
style(format!("{}:", dep_type_to_key(ty))).yellow().bold()
|
||||||
DependencyType::Peer => "peer_dependencies",
|
);
|
||||||
DependencyType::Dev => "dev_dependencies",
|
|
||||||
};
|
|
||||||
println!("{}", style(format!("{ty_name}:")).yellow().bold());
|
|
||||||
|
|
||||||
for (id, added) in set {
|
for (id, added) in set {
|
||||||
println!(
|
println!(
|
||||||
|
|
|
@ -11,7 +11,7 @@ use pesde::{
|
||||||
manifest::{
|
manifest::{
|
||||||
overrides::{OverrideKey, OverrideSpecifier},
|
overrides::{OverrideKey, OverrideSpecifier},
|
||||||
target::TargetKind,
|
target::TargetKind,
|
||||||
Manifest,
|
DependencyType, Manifest,
|
||||||
},
|
},
|
||||||
names::{PackageName, PackageNames},
|
names::{PackageName, PackageNames},
|
||||||
source::{
|
source::{
|
||||||
|
@ -352,3 +352,11 @@ pub async fn get_index(project: &Project, index: Option<&str>) -> anyhow::Result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dep_type_to_key(dep_type: DependencyType) -> &'static str {
|
||||||
|
match dep_type {
|
||||||
|
DependencyType::Standard => "dependencies",
|
||||||
|
DependencyType::Dev => "dev_dependencies",
|
||||||
|
DependencyType::Peer => "peer_dependencies",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -184,6 +184,15 @@ pub enum DependencyType {
|
||||||
Dev,
|
Dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DependencyType {
|
||||||
|
/// All possible dependency types
|
||||||
|
pub const VARIANTS: &'static [DependencyType] = &[
|
||||||
|
DependencyType::Standard,
|
||||||
|
DependencyType::Peer,
|
||||||
|
DependencyType::Dev,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
impl Manifest {
|
impl Manifest {
|
||||||
/// Get all dependencies from the manifest
|
/// Get all dependencies from the manifest
|
||||||
#[instrument(skip(self), ret(level = "trace"), level = "debug")]
|
#[instrument(skip(self), ret(level = "trace"), level = "debug")]
|
||||||
|
|
Loading…
Add table
Reference in a new issue