Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/cli/cmd/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) async fn load_flake(
}

#[tracing::instrument(skip_all)]
async fn infer_flake_input_name_url(
pub(crate) async fn infer_flake_input_name_url(
api_addr: url::Url,
flake_ref: String,
input_name: Option<String>,
Expand Down
30 changes: 30 additions & 0 deletions src/cli/cmd/get_url.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::process::ExitCode;

use clap::Parser;

use super::CommandExecute;

/// Prints the URL of a given FlakeHub flake
#[derive(Parser, Debug)]
pub(crate) struct GetURLSubcommand {
/// The FlakeHub reference to print as a URL
///
/// A FlakeHub reference is of a form like `NixOS/nixpkgs` or `NixOS/nixpkgs/0.2305.*`
pub(crate) input_ref: String,

#[clap(from_global)]
api_addr: url::Url,
}

#[async_trait::async_trait]
impl CommandExecute for GetURLSubcommand {
async fn execute(self) -> color_eyre::Result<ExitCode> {
let (_, flake_input_url) =
crate::cli::cmd::add::infer_flake_input_name_url(self.api_addr, self.input_ref, None)
.await?;

println!("{}", flake_input_url);

Ok(ExitCode::SUCCESS)
}
}
2 changes: 2 additions & 0 deletions src/cli/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub(crate) mod add;
pub(crate) mod completion;
pub(crate) mod convert;
pub(crate) mod eject;
pub(crate) mod get_url;
pub(crate) mod init;
pub(crate) mod list;
pub(crate) mod login;
Expand Down Expand Up @@ -50,6 +51,7 @@ pub trait CommandExecute {
#[derive(clap::Subcommand)]
pub(crate) enum FhSubcommands {
Add(add::AddSubcommand),
GetURL(get_url::GetURLSubcommand),
Completion(completion::CompletionSubcommand),
Init(init::InitSubcommand),
List(list::ListSubcommand),
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async fn main() -> color_eyre::Result<std::process::ExitCode> {

match cli.subcommand {
FhSubcommands::Add(add) => add.execute().await,
FhSubcommands::GetURL(get_url) => get_url.execute().await,
FhSubcommands::Init(init) => init.execute().await,
FhSubcommands::List(list) => list.execute().await,
FhSubcommands::Search(search) => search.execute().await,
Expand Down