Skip to content

Commit

Permalink
Merge pull request #70 from DeterminateSystems/cole/ds-1338-fh-add-sh…
Browse files Browse the repository at this point in the history
…ould-be-aware-of-private-flakes
  • Loading branch information
cole-h authored Oct 17, 2023
2 parents cf68f47 + 69c4f15 commit 58c7acf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ color-eyre = { version = "0.6.2", default-features = false, features = [
handlebars = "4.4.0"
indicatif = { version = "0.17.6", default-features = false }
inquire = "0.6.2"
lazy_static = "1.4.0"
nixel = "5.2.0"
once_cell = "1.18.0"
prettytable-rs = "0.10.0"
Expand Down
21 changes: 17 additions & 4 deletions src/cli/cmd/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::process::ExitCode;

use clap::Parser;
use color_eyre::eyre::WrapErr;
use reqwest::header::{HeaderValue, ACCEPT, AUTHORIZATION};
use serde::Deserialize;

use self::flake::InputsInsertionLocation;
Expand Down Expand Up @@ -191,10 +192,22 @@ pub(crate) async fn get_flakehub_project_and_url(
version: Option<&str>,
) -> color_eyre::Result<(String, url::Url)> {
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
"Accept",
reqwest::header::HeaderValue::from_static("application/json"),
);
headers.insert(ACCEPT, HeaderValue::from_static("application/json"));

let xdg = xdg::BaseDirectories::new()?;
// $XDG_CONFIG_HOME/fh/auth; basically ~/.config/fh/auth
let token_path = xdg.get_config_file("flakehub/auth");

if token_path.exists() {
let token = tokio::fs::read_to_string(&token_path)
.await
.wrap_err_with(|| format!("Could not open {}", token_path.display()))?;

headers.insert(
AUTHORIZATION,
HeaderValue::from_str(&format!("Bearer {token}"))?,
);
}

let client = reqwest::Client::builder()
.user_agent(crate::APP_USER_AGENT)
Expand Down
15 changes: 8 additions & 7 deletions src/cli/cmd/init/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ use inquire::{
ui::{Color, RenderConfig, StyleSheet, Styled},
Confirm, MultiSelect, Select, Text,
};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;

lazy_static! {
static ref MAGENTA_TEXT: StyleSheet = StyleSheet::default().with_fg(Color::DarkMagenta);
static ref GREY_TEXT: StyleSheet = StyleSheet::default().with_fg(Color::Grey);
static ref PROMPT_CONFIG: RenderConfig = RenderConfig::default()
static MAGENTA_TEXT: Lazy<StyleSheet> =
Lazy::new(|| StyleSheet::default().with_fg(Color::DarkMagenta));
static GREY_TEXT: Lazy<StyleSheet> = Lazy::new(|| StyleSheet::default().with_fg(Color::Grey));
static PROMPT_CONFIG: Lazy<RenderConfig> = Lazy::new(|| {
RenderConfig::default()
.with_prompt_prefix(Styled::new(">").with_fg(Color::LightBlue))
.with_selected_option(Some(*MAGENTA_TEXT))
.with_answer(*GREY_TEXT)
.with_help_message(*GREY_TEXT);
}
.with_help_message(*GREY_TEXT)
});

pub(crate) struct Prompt;

Expand Down
10 changes: 5 additions & 5 deletions src/cli/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) mod login;
pub(crate) mod search;
pub(crate) mod status;

use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator, TableFormat};
use reqwest::Client as HttpClient;
use serde::Serialize;
Expand All @@ -17,16 +17,16 @@ use self::{
search::SearchResult,
};

lazy_static! {
pub(crate) static ref TABLE_FORMAT: TableFormat = FormatBuilder::new()
pub(crate) static TABLE_FORMAT: Lazy<TableFormat> = Lazy::new(|| {
FormatBuilder::new()
.borders('|')
.padding(1, 1)
.separators(
&[LinePosition::Top, LinePosition::Title, LinePosition::Bottom],
LineSeparator::new('-', '+', '+', '+'),
)
.build();
}
.build()
});

#[async_trait::async_trait]
pub trait CommandExecute {
Expand Down

0 comments on commit 58c7acf

Please sign in to comment.