Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions rust/lon/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ enum Commands {
Freeze(SourceArgs),
/// Unfreeze an existing source
Unfreeze(SourceArgs),
/// Show the list of sources or a specific source
Show { name: Option<String> },

/// Bot that opens PRs for updates
Bot {
Expand Down Expand Up @@ -243,6 +245,7 @@ impl Commands {
Self::Remove(args) => remove(directory, &args),
Self::Freeze(args) => freeze(directory, &args),
Self::Unfreeze(args) => unfreeze(directory, &args),
Self::Show { name } => show(directory, name),

Self::Bot { commands } => match commands {
BotCommands::GitLab => bot(directory, &GitLab::from_env()?),
Expand Down Expand Up @@ -484,6 +487,27 @@ fn unfreeze(directory: impl AsRef<Path>, args: &SourceArgs) -> Result<()> {
Ok(())
}

fn show(directory: impl AsRef<Path>, name: Option<String>) -> Result<()> {
let mut sources = Sources::read(&directory)?;

match name {
Some(name) => {
let Some(source) = sources.get_mut(&name) else {
bail!("Source {name} doesn't exist")
};

println!("{name}:\n{source}");
}
None => {
for (name, source) in sources.iter() {
println!("{name}:\n{source}");
}
}
}

Ok(())
}

fn bot(directory: impl AsRef<Path>, forge: &impl Forge) -> Result<()> {
let base_ref = git::current_rev(&directory)?;

Expand Down
64 changes: 63 additions & 1 deletion rust/lon/src/sources.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{collections::BTreeMap, path::Path};
use std::{
collections::{BTreeMap, btree_map::Iter},
fmt,
path::Path,
};

use anyhow::{Context, Result, bail};
use nix_compat::nixhash::NixHash;
Expand Down Expand Up @@ -128,6 +132,11 @@ impl Sources {
pub fn names(&self) -> Vec<&String> {
self.map.keys().collect()
}

/// Return an iterator over the sources
pub fn iter(&self) -> Iter<'_, String, Source> {
self.map.iter()
}
}

#[derive(Clone)]
Expand Down Expand Up @@ -207,6 +216,22 @@ impl Source {
}
}

impl fmt::Display for Source {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Source::Git(s) => {
write!(f, " Type: Git\n{s}")
}
Source::GitHub(s) => {
write!(f, " Type: GitHub\n{s}")
}
Source::Tarball(s) => {
write!(f, " Type: Tarball\n{s}")
}
}
}
}

#[derive(Clone)]
pub struct GitSource {
url: String,
Expand All @@ -221,6 +246,19 @@ pub struct GitSource {
frozen: bool,
}

impl fmt::Display for GitSource {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
[
("Url", &self.url),
("Branch", &self.branch),
("Revision", &self.revision.as_str().into()),
("Frozen", &self.frozen.to_string()),
]
.iter()
.try_for_each(|(k, v)| writeln!(f, " {k}: {v}"))
}
}

impl GitSource {
pub fn new(
url: &str,
Expand Down Expand Up @@ -349,6 +387,19 @@ pub struct GitHubSource {
frozen: bool,
}

impl fmt::Display for GitHubSource {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
[
("Repository", &format!("{}/{}", &self.owner, &self.repo)),
("Branch", &self.branch),
("Revision", &self.revision.as_str().into()),
("Frozen", &self.frozen.to_string()),
]
.iter()
.try_for_each(|(k, v)| writeln!(f, " {k}: {v}"))
}
}

impl GitHubSource {
pub fn new(
owner: &str,
Expand Down Expand Up @@ -485,6 +536,17 @@ pub struct TarballSource {
frozen: bool,
}

impl fmt::Display for TarballSource {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(origin) = &self.origin {
writeln!(f, " Origin: {origin}")?;
}
[("Locked", &self.url), ("Frozen", &self.frozen.to_string())]
.iter()
.try_for_each(|(k, v)| writeln!(f, " {k}: {v}"))
}
}

#[derive(Clone)]
struct TarballFlakeRef {
url: String,
Expand Down
Loading