mirror of
https://github.com/sxyazi/yazi.git
synced 2024-11-24 01:48:00 +03:00
feat: add pack --list
subcommand to Ya CLI (#1110)
Co-authored-by: 三咲雅 · Misaki Masa <sxyazi@gmail.com>
This commit is contained in:
parent
95e960a64a
commit
add801f28e
@ -91,6 +91,9 @@ pub(super) struct CommandPack {
|
||||
/// Install all packages.
|
||||
#[arg(short = 'i', long)]
|
||||
pub(super) install: bool,
|
||||
/// List all packages.
|
||||
#[arg(short = 'l', long)]
|
||||
pub(super) list: bool,
|
||||
/// Upgrade all packages.
|
||||
#[arg(short = 'u', long)]
|
||||
pub(super) upgrade: bool,
|
||||
|
@ -36,6 +36,9 @@ async fn main() -> anyhow::Result<()> {
|
||||
if cmd.install {
|
||||
package::Package::install_from_config("plugin", false).await?;
|
||||
package::Package::install_from_config("flavor", false).await?;
|
||||
} else if cmd.list {
|
||||
package::Package::list_from_config("plugin").await?;
|
||||
package::Package::list_from_config("flavor").await?;
|
||||
} else if cmd.upgrade {
|
||||
package::Package::install_from_config("plugin", true).await?;
|
||||
package::Package::install_from_config("flavor", true).await?;
|
||||
|
@ -66,6 +66,28 @@ impl Package {
|
||||
fs::write(path, doc.to_string()).await.context("Failed to write package.toml")
|
||||
}
|
||||
|
||||
pub(crate) async fn list_from_config(section: &str) -> Result<()> {
|
||||
let path = Xdg::config_dir().join("package.toml");
|
||||
let Ok(s) = fs::read_to_string(&path).await else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let doc = s.parse::<DocumentMut>().context("Failed to parse package.toml")?;
|
||||
let Some(deps) = doc.get(section).and_then(|d| d.get("deps")) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let deps = deps.as_array().context("`deps` must be an array")?;
|
||||
println!("{section}s:");
|
||||
|
||||
for dep in deps {
|
||||
if let Some(Value::String(use_)) = dep.as_inline_table().and_then(|t| t.get("use")) {
|
||||
println!("\t{}", use_.value());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_config(s: &str) -> Result<DocumentMut> {
|
||||
let mut doc = s.parse::<DocumentMut>().context("Failed to parse package.toml")?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user