Conversation
- add pull command to fetch secrets and generate .env files - add set command to push .env content to AWS Secrets Manager - add generateEnvHeader function to add metadata comments to generated files - modify jsonToEnv to quote all values for consistency - refactor fetchSecretList into shared lib function - add comprehensive tests for new functionality - update schema.json with new config options (output, name)
- restructure src/lib.ts into separate modules in src/lib/ directory - aws.ts: AWS-related functions and types - config.ts: configuration loading and merging - env.ts: environment file parsing and JSON formatting - validation.ts: input validation and utility functions - index.ts: central exports for all lib modules - move command files to src/commands/ directory for better organization - update import paths throughout codebase for new structure - enhance set command UI messages to display file paths - dry-run mode shows input file path being previewed - upload mode shows both file path and secret name - add test coverage for file path display in dry-run mode - add CLI help message tests with comprehensive coverage
- implement delete command with recovery window support (7-30 days) - add interactive secret selection or --name flag for delete - include --recovery-days and --force flags for delete command - add confirmation prompt for secret deletion with recovery info - enhance set command with --force flag to skip overwrite confirmation - add overwrite confirmation when updating existing secrets in set - include comprehensive test coverage for delete command - update CLI help and error messages to include delete subcommand
- add init subcommand to create .e2smrc.jsonc configuration file - implement interactive confirmation for file overwrite with --force flag - migrate config format from .json to .jsonc with comment support - maintain backward compatibility with existing .json config files - add jsonc-parser dependency for parsing JSONC with error handling - move schema.json to assets/schema.json for better organization - create template.jsonc with commented examples for all config options - enhance config loading with fallback chain and parse error warnings - add comprehensive tests for init command and config parsing - update README with init command documentation and JSONC examples
🦋 Changeset detectedLatest commit: d602e5b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
この PR は、既存の単一 get コマンドの CLI を、init / set / get / pull / delete のサブコマンドを持つ環境変数管理ツールへ拡張し、設定ファイルの JSONC 対応やライブラリ分割を含む大規模リファクタリングを行うものです。
Changes:
- ライブラリ層を
aws / config / env / validationに分割し、コマンドはsrc/commands/以下のサブコマンド (set / get / pull / delete / init) として再構成。 - 設定ファイル
.e2smrc.jsonc/.jsonのロード処理を JSONC・トレーリングカンマ対応、パースエラー時のフォールバック・警告出力付きで実装。 set/pull/delete/init各コマンドに対して、対話的 UX・上書き確認・不正フラグ検知などを追加し、それぞれに対応するテストを追加。
Reviewed changes
Copilot reviewed 26 out of 28 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/validation.ts | フラグ名バリデーション(未知オプション検出)とテンプレートモード関連のフラグ整合チェックをライブラリ化。 |
| src/lib/validation.test.ts | toKebabCase・未知フラグ検出・テンプレートモード判定と競合検知のユニットテスト。 |
| src/lib/index.ts | aws/config/env/validation のファサードを提供し、コマンド側から一貫した import 先を定義。 |
| src/lib/env.ts | .env パーサー・JSON→.env 変換・ヘッダ生成・色付き JSON フォーマッタを分離実装。 |
| src/lib/env.test.ts | .env パーサーと jsonToEnv・generateEnvHeader の正常系・端ケースのテスト。 |
| src/lib/config.ts | .e2smrc.jsonc/.json の検索順序付きロード(JSONC/コメント/トレーリングカンマ対応)と mergeWithConfig を実装。 |
| src/lib/config.test.ts | JSONC パターン・フォールバック挙動・パースエラー時の warn とスキップ、およびマージロジックのテスト。 |
| src/lib/aws.ts | exec ラッパーと aws secretsmanager list-secrets を叩く fetchSecretList を実装。 |
| src/lib/aws.test.ts | exec の標準出力・エラー時挙動の簡易テスト。 |
| src/lib.ts | 旧モノリシックな lib 実装を削除し、新しいモジュール構成に移行。 |
| src/index.ts | ルート e2sm コマンドを定義し、サブコマンド (init/set/get/pull/delete) を委譲、サブコマンド未指定時のエラーメッセージを追加。 |
| src/index.test.ts | ルート CLI の --help/-h/--version、サブコマンド未指定時のエラー、各サブコマンドの help/未知フラグ/代表的エラーパス・設定ファイル読み込みの統合テスト。 |
| src/commands/set.ts | .env ファイルを読み込み JSON 化し、テンプレートモードや上書き確認付きで Secrets Manager に create/put-secret-value する set コマンドを実装。 |
| src/commands/set.test.ts | set コマンドのフラグ定義とメタデータ(名前・説明)のテスト。 |
| src/commands/pull.ts | Secrets Manager からシークレット一覧を取得・選択し、.env ファイルへ書き出す pull コマンドを実装(既存ファイルの上書き確認付き)。 |
| src/commands/pull.test.ts | pull コマンドのフラグ定義と説明文のテスト。 |
| src/commands/init.ts | テンプレート JSONC から .e2smrc.jsonc を生成・必要に応じて上書きする init コマンドを実装。 |
| src/commands/init.test.ts | init コマンドのフラグ定義テストと、テンプレート JSONC のスキーマ・コメント有無検証。 |
| src/commands/get.ts | Secrets Manager からシークレットを取得し、JSON なら整形表示・それ以外は生出力する get コマンドを、共有 fetchSecretList を使う形に変更。 |
| src/commands/get.test.ts | get コマンドのフラグ定義・メタデータのテスト。 |
| src/commands/delete.ts | シークレット一覧からの選択または --name 指定で、リカバリ期間付き削除を行う delete コマンドを実装(入力バリデーション・確認プロンプト付き)。 |
| src/commands/delete.test.ts | delete コマンドのフラグ定義テスト。 |
| package.json | 公開ファイルを assets ディレクトリに変更し、JSONC 対応のため jsonc-parser を devDependency に追加。 |
| bun.lock | jsonc-parser 追加に伴うロックファイル更新。 |
| assets/template.jsonc | .e2smrc.jsonc 用のコメント付きテンプレート(スキーマ参照と主要オプションのサンプル)を追加。 |
| assets/schema.json | 設定ファイル用 JSON Schema を assets/ 以下に移動し、output・name プロパティを追記。 |
| README.md | コマンド体系の説明を init/set/get/pull/delete ベースに刷新し、JSONC 設定ファイルと探索順序・優先順位のドキュメントを更新。 |
| .changeset/vast-dancers-teach.md | 本 PR の変更内容を示す changeset(マイナーバージョンアップ)を追加。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export function jsonToEnv(data: Record<string, string>): string { | ||
| return Object.entries(data) | ||
| .map(([key, value]) => { | ||
| const escaped = value.replace(/"/g, '\\"'); |
There was a problem hiding this comment.
jsonToEnv は Record<string, string> を想定していますが、pull コマンドでは JSON.parse(secretString) の戻り値(任意の JSON)に対してそのまま呼び出しているため、値に数値やオブジェクトなど文字列以外が含まれていると value.replace 呼び出しでランタイムエラーになります。AWS Secrets Manager 上のシークレットがこのツール以外から作成・更新されているケースも考えられるので、ここで String(value) で文字列化するか、typeof value === "string" の場合のみ処理するなど、非文字列値でも安全に動作するようにしておく方が良いと思います。
| const escaped = value.replace(/"/g, '\\"'); | |
| const stringValue = typeof value === "string" ? value : String(value); | |
| const escaped = stringValue.replace(/"/g, '\\"'); |
| console.error("Error: Please specify a subcommand (init, set, get, pull, or delete)"); | ||
| console.error(""); | ||
| console.error("Usage:"); | ||
| console.error(" e2sm init - Initialize .e2smrc.json configuration file"); |
There was a problem hiding this comment.
ここでは e2sm init が「.e2smrc.json configuration file」を初期化すると表示していますが、実際に init コマンドが作成するのは .e2smrc.jsonc であり、README やテンプレートとも .jsonc に統一されています。ユーザーがどのファイルを編集すべきか混乱しないように、このメッセージも .e2smrc.jsonc に合わせておくと良いと思います。
| console.error(" e2sm init - Initialize .e2smrc.json configuration file"); | |
| console.error(" e2sm init - Initialize .e2smrc.jsonc configuration file"); |
Issue
N/A - Add essential subcommands for complete environment variable management
Changes
pullcommand to download secrets from AWS Secrets Manager and generate .env filessetcommand to upload .env files to AWS Secrets Manager with overwrite confirmationdeletecommand to schedule secret deletion with configurable retention periodinitcommand to create .e2smrc.jsonc configuration file with commented examplesVerification
Additional Notes
This PR represents a major evolution of the CLI tool from a simple
getcommand to a complete environment variable management suite. Key architectural improvements:src/commands/The changes maintain full backward compatibility with existing .json config files while providing an upgrade path to the more user-friendly .jsonc format.