Skip to content

feat: add pull, set, delete, and init subcommands#8

Merged
lemtoc merged 6 commits into
mainfrom
v1
Jan 27, 2026
Merged

feat: add pull, set, delete, and init subcommands#8
lemtoc merged 6 commits into
mainfrom
v1

Conversation

@lemtoc
Copy link
Copy Markdown
Owner

@lemtoc lemtoc commented Jan 27, 2026

Issue

N/A - Add essential subcommands for complete environment variable management

Changes

  • Add pull command to download secrets from AWS Secrets Manager and generate .env files
  • Add set command to upload .env files to AWS Secrets Manager with overwrite confirmation
  • Add delete command to schedule secret deletion with configurable retention period
  • Add init command to create .e2smrc.jsonc configuration file with commented examples
  • Support JSONC format in config files (comments and trailing commas)
  • Add parse error handling with fallback to next config candidate
  • Reorganize codebase structure: move commands to src/commands/ and split lib into modules
  • Improve UI messages and user experience across all commands
  • Add comprehensive test coverage for all new functionality

Verification

  • Tests pass successfully
  • No lint/type errors
  • No breaking changes introduced (backward compatibility maintained)
  • Changeset file created (minor version bump)

Additional Notes

This PR represents a major evolution of the CLI tool from a simple get command to a complete environment variable management suite. Key architectural improvements:

  • Modular design: Commands are now separated into individual files under src/commands/
  • Library organization: Core functionality split into focused modules (aws, config, env, validation)
  • JSONC support: Users can now add comments to config files for better documentation
  • Robust config loading: Graceful error handling with clear warnings and fallback behavior
  • Interactive UX: Confirmation prompts for destructive operations

The changes maintain full backward compatibility with existing .json config files while providing an upgrade path to the more user-friendly .jsonc format.

- 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-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 27, 2026

🦋 Changeset detected

Latest commit: d602e5b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
e2sm Minor

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

@lemtoc lemtoc requested a review from Copilot January 27, 2026 06:40
@lemtoc lemtoc self-assigned this Jan 27, 2026
@lemtoc lemtoc merged commit 1c38a0a into main Jan 27, 2026
8 checks passed
@lemtoc lemtoc deleted the v1 branch January 27, 2026 06:46
@github-actions github-actions Bot mentioned this pull request Jan 27, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 パーサーと jsonToEnvgenerateEnvHeader の正常系・端ケースのテスト。
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/ 以下に移動し、outputname プロパティを追記。
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.

Comment thread src/lib/env.ts
export function jsonToEnv(data: Record<string, string>): string {
return Object.entries(data)
.map(([key, value]) => {
const escaped = value.replace(/"/g, '\\"');
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonToEnvRecord<string, string> を想定していますが、pull コマンドでは JSON.parse(secretString) の戻り値(任意の JSON)に対してそのまま呼び出しているため、値に数値やオブジェクトなど文字列以外が含まれていると value.replace 呼び出しでランタイムエラーになります。AWS Secrets Manager 上のシークレットがこのツール以外から作成・更新されているケースも考えられるので、ここで String(value) で文字列化するか、typeof value === "string" の場合のみ処理するなど、非文字列値でも安全に動作するようにしておく方が良いと思います。

Suggested change
const escaped = value.replace(/"/g, '\\"');
const stringValue = typeof value === "string" ? value : String(value);
const escaped = stringValue.replace(/"/g, '\\"');

Copilot uses AI. Check for mistakes.
Comment thread src/index.ts
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");
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでは e2sm init が「.e2smrc.json configuration file」を初期化すると表示していますが、実際に init コマンドが作成するのは .e2smrc.jsonc であり、README やテンプレートとも .jsonc に統一されています。ユーザーがどのファイルを編集すべきか混乱しないように、このメッセージも .e2smrc.jsonc に合わせておくと良いと思います。

Suggested change
console.error(" e2sm init - Initialize .e2smrc.json configuration file");
console.error(" e2sm init - Initialize .e2smrc.jsonc configuration file");

Copilot uses AI. Check for mistakes.
Comment thread package.json
@lemtoc lemtoc restored the v1 branch January 27, 2026 06:50
@lemtoc lemtoc deleted the v1 branch January 27, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants