diff --git a/AGENTS.md b/AGENTS.md index cda542e..879bfc5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -153,7 +153,6 @@ secrets init # 提示输入主密码,Argon2id 派生主密钥后存入 OS - TTY(终端直接运行)→ 默认 `text` - 非 TTY(管道/重定向/AI 调用)→ 自动 `json-compact` - 显式 `-o json` → 美化 JSON -- 显式 `-o env` → KEY=VALUE(可 source) --- @@ -182,7 +181,7 @@ secrets init # --limit 20 | 50(默认 50) # --offset 0 | 10 | 20(分页偏移) # --sort name(默认)| updated | created -# -o / --output text | json | json-compact | env +# -o / --output text | json | json-compact # 发现概览(起步推荐) secrets search --summary --limit 20 @@ -222,10 +221,6 @@ secrets search -n refining --summary --limit 10 --offset 10 # 管道 / AI 调用(非 TTY 自动 json-compact) secrets search -n refining --kind service | jq '.[].name' - -# 导出 metadata 为 env 文件(单条记录) -secrets search -n refining --kind service --name gitea -o env \ - > ~/.config/gitea/config.env ``` --- diff --git a/Cargo.lock b/Cargo.lock index 457e8c6..90a85d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1836,7 +1836,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "secrets" -version = "0.7.4" +version = "0.7.5" dependencies = [ "aes-gcm", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 09aee0f..28d4f70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "secrets" -version = "0.7.4" +version = "0.7.5" edition = "2024" [dependencies] diff --git a/README.md b/README.md index 49d1f68..4510793 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,6 @@ secrets run -n refining --kind service --name gitea -- printenv | 场景 | 推荐命令 | |------|----------| | AI 解析 / 管道处理 | `-o json` 或 `-o json-compact` | -| 写入 metadata `.env` 文件 | `-o env` | | 注入 secrets 到环境变量 | `inject` / `run` | | 人类查看 | 默认 `text`(TTY 下自动启用) | | 非 TTY(管道/重定向) | 自动 `json-compact` | @@ -87,10 +86,6 @@ secrets run -n refining --kind service --name gitea -- printenv # 管道直接 jq 解析(非 TTY 自动 json-compact) secrets search -n refining --kind service | jq '.[].name' -# 导出 metadata 为可 source 的 env 文件(单条记录) -secrets search -n refining --kind service --name gitea -o env \ - > ~/.config/gitea/config.env - # 需要 secrets 时,使用 inject / run secrets inject -n refining --kind service --name gitea > ~/.config/gitea/secrets.env secrets run -n refining --kind service --name gitea -- ./deploy.sh diff --git a/src/commands/search.rs b/src/commands/search.rs index 29400df..45fabdb 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -55,24 +55,6 @@ pub async fn run(pool: &PgPool, args: SearchArgs<'_>) -> Result<()> { }; println!("{}", out); } - OutputMode::Env => { - if rows.len() > 1 { - anyhow::bail!( - "env output requires exactly one record; got {}. Add more filters.", - rows.len() - ); - } - if let Some(row) = rows.first() { - let map = build_metadata_env_map(row, ""); - let mut pairs: Vec<(String, String)> = map.into_iter().collect(); - pairs.sort_by(|a, b| a.0.cmp(&b.0)); - for (k, v) in pairs { - println!("{}={}", k, shell_quote(&v)); - } - } else { - eprintln!("No records found."); - } - } OutputMode::Text => { if rows.is_empty() { println!("No records found."); @@ -302,12 +284,6 @@ pub fn build_injected_env_map( Ok(map) } -/// Quote a value for safe shell / env output. Wraps in single quotes, -/// escaping any single quotes within the value. -fn shell_quote(s: &str) -> String { - format!("'{}'", s.replace('\'', "'\\''")) -} - /// Convert a JSON value to its string representation suitable for env vars. fn json_value_to_env_string(v: &Value) -> String { match v { diff --git a/src/main.rs b/src/main.rs index 7fb1ac4..a1f50da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,7 +126,7 @@ EXAMPLES: /// Secret entry: key=value, key:=, key=@file, or nested:path@file #[arg(long = "secret", short = 's')] secrets: Vec, - /// Output format: text (default on TTY), json, json-compact, env + /// Output format: text (default on TTY), json, json-compact #[arg(short, long = "output")] output: Option, }, @@ -135,7 +135,7 @@ EXAMPLES: /// /// Supports fuzzy search (-q), exact lookup (--name), field extraction (-f), /// summary view (--summary), pagination (--limit / --offset), and structured - /// output (-o json / json-compact / env). When stdout is not a TTY, output + /// output (-o json / json-compact). When stdout is not a TTY, output /// defaults to json-compact automatically. #[command(after_help = "EXAMPLES: # Discover all records (summary, safe default limit) @@ -157,9 +157,6 @@ EXAMPLES: secrets search -n refining --kind service --name gitea \\ -f metadata.url -f metadata.default_org - # Export metadata as env vars (single record only) - secrets search -n refining --kind service --name gitea -o env - # Inject decrypted secrets only when needed secrets inject -n refining --kind service --name gitea secrets run -n refining --kind service --name gitea -- printenv @@ -207,7 +204,7 @@ EXAMPLES: /// Sort order: name (default), updated, created #[arg(long, default_value = "name")] sort: String, - /// Output format: text (default on TTY), json, json-compact, env + /// Output format: text (default on TTY), json, json-compact #[arg(short, long = "output")] output: Option, }, diff --git a/src/output.rs b/src/output.rs index c62a6b3..d9b690d 100644 --- a/src/output.rs +++ b/src/output.rs @@ -12,8 +12,6 @@ pub enum OutputMode { Json, /// Single-line JSON (default when stdout is NOT a TTY, e.g. piped to jq) JsonCompact, - /// KEY=VALUE pairs suitable for `source` or `.env` files - Env, } impl FromStr for OutputMode { @@ -24,9 +22,8 @@ impl FromStr for OutputMode { "text" => Ok(Self::Text), "json" => Ok(Self::Json), "json-compact" => Ok(Self::JsonCompact), - "env" => Ok(Self::Env), other => Err(anyhow::anyhow!( - "Unknown output format '{}'. Valid: text, json, json-compact, env", + "Unknown output format '{}'. Valid: text, json, json-compact", other )), }