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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
build-artifacts:
runs-on: ${{ matrix.systems.runner }}
permissions:
id-token: "write"
contents: "read"
id-token: write
contents: read
strategy:
matrix:
systems:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
flake-check:
runs-on: UbuntuLatest32Cores128G
permissions:
id-token: "write"
contents: "read"
id-token: write
contents: read
steps:
- uses: actions/checkout@v4

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
jobs:
rust-fmt-and-clippy:
runs-on: UbuntuLatest32Cores128G
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/update-flake-lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
jobs:
lockfile:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/determinate-nix-action@main
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ license = "Apache 2.0"
repository = "https://github.com/DeterminateSystems/fh"

[dependencies]
axum = { version = "0.7.5", features = ["macros"] }
chrono = { version = "0.4.31", default-features = false, features = ["clock"] }
axum = { version = "0.7.5", default-features = false, features = ["macros"] }
chrono = { version = "0.4.31", default-features = false, features = [
"clock",
"serde",
] }
clap = { version = "4.3.2", default-features = false, features = [
"color",
"derive",
"env",
"error-context",
"help",
"std",
"error-context",
] }
clap_complete = { version = "4.4.0", default-features = false }
color-eyre = { version = "0.6.2", default-features = false, features = [
Expand All @@ -25,7 +28,6 @@ csv = { version = "1.3.0", default-features = false }
gethostname = { version = "0.4.3", default-features = false }
handlebars = { version = "4.4.0", default-features = false }
http = { version = "1.0", default-features = false }
http-body-util = { version = "0.1", default-features = false } # TODO(colemickens): revisit/remove
hyper = { version = "1.0.0", features = ["full"] }
hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] }
indicatif = { version = "0.17.6", default-features = false }
Expand All @@ -45,7 +47,10 @@ reqwest = { version = "0.11", default-features = false, features = [
semver = { version = "1.0.18", default-features = false, features = ["serde"] }
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.105", default-features = false }
tabled = { version = "0.14.0", features = ["color"] }
tabled = { version = "0.14.0", default-features = false, features = [
"color",
"derive",
] }
tempfile = { version = "3.10.1", default-features = false }
thiserror = { version = "1.0.44", default-features = false }
tokio = { version = "1.44.2", default-features = false, features = ["full"] }
Expand All @@ -65,5 +70,5 @@ whoami = { version = "1.5.1", default-features = false }
xdg = { version = "2.5.2", default-features = false }

[dev-dependencies]
axum = { version = "0.7.5", features = ["macros"] }
axum = { version = "0.7.5", default-features = false, features = ["macros"] }
axum-test = { version = "15.3.0", default-features = false }
10 changes: 5 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 36 additions & 46 deletions src/cli/cmd/list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{DateTime, Utc};
use clap::{Parser, Subcommand};
use indicatif::{ProgressBar, ProgressStyle};
use owo_colors::OwoColorize;
Expand Down Expand Up @@ -87,9 +88,28 @@ pub(crate) struct Org {
pub(crate) name: String,
}

#[derive(Deserialize, Serialize)]
#[derive(Tabled, Deserialize, Serialize)]
pub(crate) struct Release {
#[tabled(rename = "Simplified version", display_with = "bold")]
pub(crate) simplified_version: String,
#[tabled(rename = "Version", display_with = "dimmed")]
pub(crate) version: String,
#[tabled(rename = "Revision", display_with = "dimmed")]
pub(crate) revision: String,
#[tabled(rename = "Published at", display_with = "tabled_opt_dim")]
pub(crate) published_at: Option<DateTime<Utc>>,
#[tabled(rename = "Updated at", display_with = "tabled_opt_dim")]
pub(crate) updated_at: Option<DateTime<Utc>>,
#[tabled(rename = "Commit count", display_with = "tabled_opt_dim")]
pub(crate) commit_count: Option<i64>,
}

// Function for handling generic Option<T> in Tabled (dimmed)
fn tabled_opt_dim<T: std::fmt::Display>(v: &Option<T>) -> String {
match v {
Some(t) => dimmed(t.to_string()),
None => String::new(),
}
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -243,36 +263,27 @@ impl CommandExecute for ListSubcommand {

let flake = Flake::try_from(flake)?;

match FlakeHubClient::releases(
let releases = FlakeHubClient::releases(
self.api_addr.as_ref(),
&flake.org,
&flake.project,
limit,
)
.await
{
Ok(releases) => {
let rows = releases
.into_iter()
.map(Into::into)
.collect::<Vec<ReleaseRow>>();

if rows.is_empty() {
eprintln!("No results");
} else if self.json {
print_json(&rows)?;
} else if std::io::stdout().is_terminal() {
let mut table = Table::new(rows);
table.with(DEFAULT_STYLE.clone());
println!("{table}");
} else {
let mut writer = csv::Writer::from_writer(std::io::stdout());
for row in rows {
writer.serialize(row)?;
}
}
.await?;

if releases.is_empty() {
eprintln!("No results");
} else if self.json {
print_json(&releases)?;
} else if std::io::stdout().is_terminal() {
let mut table = Table::new(releases);
table.with(DEFAULT_STYLE.clone());
println!("{table}");
} else {
let mut writer = csv::Writer::from_writer(std::io::stdout());
for release in releases {
writer.serialize(release)?;
}
Err(e) => return Err(e.into()),
}
}
Versions {
Expand Down Expand Up @@ -332,10 +343,8 @@ fn string_has_whitespace(s: &str) -> bool {
#[derive(Tabled, serde::Serialize)]
struct OrgRow {
#[tabled(rename = "Organization", display_with = "bold")]
#[serde(rename = "Organization")]
organization: String,
#[tabled(rename = "FlakeHub URL", display_with = "dimmed")]
#[serde(rename = "FlakeHub URL")]
flakehub_url: Url,
}

Expand All @@ -353,13 +362,10 @@ impl From<Org> for OrgRow {
#[derive(Tabled, serde::Serialize)]
struct VersionRow {
#[tabled(rename = "Simplified version", display_with = "bold")]
#[serde(rename = "Simplified version")]
simplified_version: semver::Version,
#[tabled(rename = "FlakeHub URL", display_with = "dimmed")]
#[serde(rename = "FlakeHub URL")]
flakehub_url: Url,
#[tabled(rename = "Full version", display_with = "dimmed")]
#[serde(rename = "Full version")]
full_version: semver::Version,
}

Expand All @@ -384,10 +390,8 @@ impl From<(Flake, Version)> for VersionRow {
#[derive(Tabled, serde::Serialize)]
struct FlakeRow {
#[tabled(rename = "Flake", display_with = "bold")]
#[serde(rename = "Flake")]
flake: String,
#[tabled(rename = "FlakeHub URL", display_with = "dimmed")]
#[serde(rename = "FlakeHub URL")]
flakehub_url: Url,
}

Expand All @@ -400,20 +404,6 @@ impl From<Flake> for FlakeRow {
}
}

#[derive(Tabled, serde::Serialize)]
pub(crate) struct ReleaseRow {
#[serde(rename = "Version")]
pub(crate) version: String,
}

impl From<Release> for ReleaseRow {
fn from(value: Release) -> Self {
Self {
version: value.version,
}
}
}

fn dimmed(v: impl ToString) -> String {
v.to_string().dimmed().to_string()
}
Expand Down