From 48f3b293a4467779241e95db4aa9a47e314068c9 Mon Sep 17 00:00:00 2001 From: nicodes Date: Sun, 8 Nov 2026 18:11:31 +0100 Subject: [PATCH 1/3] Use process credentials without dotenv fallback --- README.md | 6 +++--- src/config.rs | 27 +++------------------------ tests/cli_test.py | 8 ++++++-- 3 files changed, 12 insertions(+), 29 deletions(-) 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