diff --git a/.github/readme-source.toml b/.github/readme-source.toml index 51dcfd5..57d697f 100644 --- a/.github/readme-source.toml +++ b/.github/readme-source.toml @@ -1,5 +1,5 @@ version = 1 -sha256 = "671c20fbff6a084e6b665dd5d5a7755fd7768d282c2c406e45e1c7ce4e798ae9" +sha256 = "3fce97e7eef296ae3e7cfa494fbf1ab6cb5fe132b4ccc51f4a4f182f308964fe" [history] forbidden_commits = ["3cbdabb71650fbca119b17e89ceed577f6bf81cd"] diff --git a/README.md b/README.md index bd5b3ba..f8327f6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + # pxlb @@ -71,7 +71,7 @@ export PIXELLAB_API_KEY="..." pxlb balance ``` -You can also put `PIXELLAB_API_KEY=...` in a `.env` file in the directory where you run `pxlb`, or pass `--token ` for a single command. +Supply `PIXELLAB_API_KEY` through your process environment, including an approved Preview credential injected by `ghenv dev -- pxlb balance`. Keep public development defaults in Mise. Pass `--token ` to override the process value for a single command. ## Command Model @@ -125,7 +125,7 @@ pxlb --version | Flag | Purpose | |---|---| -| `--token ` | PixelLab API key. Overrides `PIXELLAB_API_KEY` and `.env`. | +| `--token ` | PixelLab API key. Overrides `PIXELLAB_API_KEY`. | | `--base-url ` | API base URL. Defaults to `https://api.pixellab.ai/v2`. | | `--http-method ` | Override inferred method for colliding routes. Usually only needed for delete. | | `--json` | Print raw JSON response. | diff --git a/src/config.rs b/src/config.rs index d880a2b..d468f8d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,6 @@ use crate::Result; use serde::Deserialize; -use std::{collections::BTreeMap, fs, time::Duration}; +use std::{collections::BTreeMap, time::Duration}; #[derive(Clone, Deserialize)] pub struct Endpoint { @@ -74,28 +74,7 @@ fn duration(value: &str) -> Result { }) } pub fn token() -> String { - if let Ok(token) = std::env::var("PIXELLAB_API_KEY") - && !token.is_empty() - { - return token; - } - let Ok(text) = fs::read_to_string(".env") else { - return String::new(); - }; - let mut token = String::new(); - for line in text.lines() { - let line = line.trim(); - if line.starts_with('#') { - continue; - } - let line = line.strip_prefix("export ").unwrap_or(line); - if let Some((key, value)) = line.split_once('=') - && key.trim() == "PIXELLAB_API_KEY" - { - token = value.trim().trim_matches(['\"', '\'']).into(); - } - } - token + std::env::var("PIXELLAB_API_KEY").unwrap_or_default() } impl Config { pub fn parse(args: &[String]) -> Result { @@ -247,7 +226,7 @@ pub fn display(path: &str) -> String { .join("/") } pub fn help() -> String { - let mut text="pxlb - PixelLab v2 API CLI\n\nUsage:\n pxlb [flags]\n pxlb --version\n\nGlobal flags:\n --token PixelLab API key; overrides PIXELLAB_API_KEY and .env.\n --base-url API base URL; defaults to https://api.pixellab.ai/v2.\n --http-method Override inferred HTTP method for colliding routes.\n --body-json Send a raw JSON request body.\n --wait Poll returned background jobs until completion.\n --poll-interval