Skip to content

Commit

Permalink
feat: include package revision hash in ya pack --list (#1884)
Browse files Browse the repository at this point in the history
Co-authored-by: sxyazi <[email protected]>
  • Loading branch information
yudai0804 and sxyazi authored Nov 3, 2024
1 parent 565f9cc commit 6086134
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 8 additions & 5 deletions yazi-cli/src/package/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl Package {
let deps = deps.as_array_mut().context("`deps` must be an array")?;
for dep in deps.iter_mut() {
let dep = dep.as_inline_table_mut().context("Dependency must be an inline table")?;
let use_ = dep.get("use").and_then(|d| d.as_str()).context("Missing `use` field")?;
let rev = dep.get("rev").and_then(|d| d.as_str());
let use_ = dep.get("use").and_then(Value::as_str).context("Missing `use` field")?;
let rev = dep.get("rev").and_then(Value::as_str);

let mut package = Package::new(use_, rev);
if upgrade {
Expand Down Expand Up @@ -81,8 +81,11 @@ impl Package {
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());
let Some(dep) = dep.as_inline_table() else { continue };
match (dep.get("use").and_then(Value::as_str), dep.get("rev").and_then(Value::as_str)) {
(Some(use_), None) => println!("\t{use_}"),
(Some(use_), Some(rev)) => println!("\t{use_} ({rev})"),
_ => {}
}
}
Ok(())
Expand Down Expand Up @@ -119,7 +122,7 @@ impl Package {
fn same(v: &Value, name: &str) -> bool {
v.as_inline_table()
.and_then(|t| t.get("use"))
.and_then(|v| v.as_str())
.and_then(Value::as_str)
.is_some_and(|s| Package::new(s, None).name() == Some(name))
}

Expand Down
18 changes: 7 additions & 11 deletions yazi-shared/src/event/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,32 @@ impl Cmd {
pub fn get(&self, name: &str) -> Option<&Data> { self.args.get(name) }

#[inline]
pub fn str(&self, name: &str) -> Option<&str> { self.args.get(name).and_then(Data::as_str) }
pub fn str(&self, name: &str) -> Option<&str> { self.get(name).and_then(Data::as_str) }

#[inline]
pub fn bool(&self, name: &str) -> bool {
self.args.get(name).and_then(Data::as_bool).unwrap_or(false)
}
pub fn bool(&self, name: &str) -> bool { self.maybe_bool(name).unwrap_or(false) }

#[inline]
pub fn maybe_bool(&self, name: &str) -> Option<bool> {
self.args.get(name).and_then(Data::as_bool)
}
pub fn maybe_bool(&self, name: &str) -> Option<bool> { self.get(name).and_then(Data::as_bool) }

#[inline]
pub fn first(&self) -> Option<&Data> { self.args.get("0") }
pub fn first(&self) -> Option<&Data> { self.get("0") }

// --- Take
#[inline]
pub fn take(&mut self, name: &str) -> Option<Data> { self.args.remove(name) }

#[inline]
pub fn take_str(&mut self, name: &str) -> Option<String> {
if let Some(Data::String(s)) = self.args.remove(name) { Some(s) } else { None }
if let Some(Data::String(s)) = self.take(name) { Some(s) } else { None }
}

#[inline]
pub fn take_first(&mut self) -> Option<Data> { self.args.remove("0") }
pub fn take_first(&mut self) -> Option<Data> { self.take("0") }

#[inline]
pub fn take_first_str(&mut self) -> Option<String> {
if let Some(Data::String(s)) = self.args.remove("0") { Some(s) } else { None }
if let Some(Data::String(s)) = self.take_first() { Some(s) } else { None }
}

#[inline]
Expand Down

0 comments on commit 6086134

Please sign in to comment.