Skip to content

Commit ee71c4a

Browse files
committed
docs: comprehensive README update with examples and troubleshooting
- Add detailed usage examples with real output - Include AWS, Kubernetes, Azure integration examples - Add troubleshooting section for PATH and clipboard issues - Document .env parsing features and supported formats - Add development section with project structure - Update security information to reflect current features - Improve overall documentation quality and completeness
1 parent 787f839 commit ee71c4a

File tree

1 file changed

+149
-44
lines changed

1 file changed

+149
-44
lines changed

README.md

Lines changed: 149 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -74,121 +74,226 @@ make build && make install
7474
### Basic Usage
7575

7676
```bash
77-
# Convert .env in current directory
77+
# Convert .env in current directory (JSON to stdout + clipboard)
7878
env2json
7979

80-
# Specify input file
81-
env2json --input .env.production
82-
env2json --input /path/to/.env
80+
# Convert specific .env file
81+
env2json -input .env.production
82+
env2json -input /path/to/.env
8383

84-
# Save output to file
85-
env2json --output secrets.json
86-
env2json --input .env.prod --output prod-secrets.json
84+
# Save output to file (no clipboard)
85+
env2json -output secrets.json
86+
env2json -input .env.prod -output prod-secrets.json
8787
```
8888

8989
### Examples
9090

91-
#### Convert local .env file
91+
#### Convert local .env file (output to console + clipboard)
9292
```bash
9393
$ env2json
94-
✅ Successfully converted .env to JSON (5 variables):
95-
9694
{
9795
"API_KEY": "abc123def456",
9896
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb",
9997
"NODE_ENV": "development",
10098
"PORT": "3000",
101-
"SECRET_KEY": "mysecretkey"
99+
"DEBUG": "true"
102100
}
101+
# ↑ JSON automatically copied to clipboard!
102+
```
103103

104-
📋 JSON copied to clipboard! Ready to paste into AWS Secrets Manager or other services.
105-
💡 To save to file instead: env2json --output secrets.json
106-
107-
📋 Variables found:
108-
API_KEY: [MASKED]
109-
DATABASE_URL: postgresql://user:pass@localhost:5432/mydb
110-
NODE_ENV: development
111-
PORT: 3000
112-
SECRET_KEY: [MASKED]
104+
#### Convert specific .env file
105+
```bash
106+
$ env2json -input .env.production
107+
{
108+
"API_SECRET": "prod_secret_key",
109+
"DATABASE_URL": "postgresql://prod-server:5432/app",
110+
"ENVIRONMENT": "production"
111+
}
113112
```
114113

115-
#### Save to file for AWS import
114+
#### Save to file instead of clipboard
116115
```bash
117-
$ env2json --output aws-secrets.json
118-
✅ Successfully converted .env to JSON and saved to aws-secrets.json (5 variables)
116+
$ env2json -output secrets.json
117+
Saved to secrets.json (5 variables)
118+
119+
$ cat secrets.json
120+
{
121+
"API_KEY": "abc123def456",
122+
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb",
123+
"NODE_ENV": "development",
124+
"PORT": "3000",
125+
"DEBUG": "true"
126+
}
119127
```
120128

121-
#### Import specific environment file
129+
#### Error handling examples
122130
```bash
123-
$ env2json --input .env.production --output prod-secrets.json
124-
✅ Successfully converted .env.production to JSON and saved to prod-secrets.json (8 variables)
131+
$ env2json
132+
No .env file found in current directory.
133+
Use --input flag to specify a different .env file:
134+
env2json --input /path/to/.env
135+
env2json --input .env.production
136+
137+
$ env2json -input nonexistent.env
138+
File not found: nonexistent.env
125139
```
126140

127141
### AWS Secrets Manager Integration
128142

129-
After generating the JSON file, you can import it directly into AWS Secrets Manager:
143+
#### Method 1: Direct clipboard paste (recommended)
144+
```bash
145+
# Convert .env and copy to clipboard
146+
env2json
130147

148+
# Then paste directly in AWS Console Secrets Manager
149+
# Or use AWS CLI with clipboard:
150+
aws secretsmanager create-secret \
151+
--name "my-app-secrets" \
152+
--secret-string "$(pbpaste)" # macOS
153+
# --secret-string "$(xclip -o)" # Linux
154+
```
155+
156+
#### Method 2: File-based import
131157
```bash
132158
# Generate secrets file
133-
env2json --output secrets.json
159+
env2json -output secrets.json
134160

135161
# Import to AWS Secrets Manager
136162
aws secretsmanager create-secret \
137163
--name "my-app-secrets" \
138164
--secret-string file://secrets.json
139165
```
140166

141-
## Error Handling
167+
### Other Cloud Services
142168

143-
The tool provides helpful error messages and suggestions:
169+
#### Kubernetes Secrets
170+
```bash
171+
# Convert and create k8s secret
172+
env2json | kubectl create secret generic my-app-secrets --from-file=/dev/stdin
144173

174+
# Or save to file first
175+
env2json -output secrets.json
176+
kubectl create secret generic my-app-secrets --from-file=secrets.json
177+
```
178+
179+
#### Azure Key Vault
180+
```bash
181+
env2json -output secrets.json
182+
az keyvault secret set --vault-name MyKeyVault --name app-secrets --file secrets.json
183+
```
184+
185+
## Troubleshooting
186+
187+
### PATH Issues
188+
If `env2json` command is not found after installation:
189+
190+
```bash
191+
# Check if binary exists
192+
ls -la ~/.local/bin/env2json # Linux
193+
ls -la ~/bin/env2json # macOS
194+
195+
# Add to PATH manually
196+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # Linux
197+
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc # macOS
198+
199+
# Reload shell
200+
source ~/.bashrc # or ~/.zshrc
201+
```
202+
203+
### Clipboard Issues
204+
If clipboard doesn't work:
205+
- **macOS**: Should work out of the box
206+
- **Linux**: Install `xclip` or `xsel`: `sudo apt install xclip`
207+
- **Windows WSL**: Install `clip` (usually pre-installed)
208+
209+
### Common Issues
145210
```bash
211+
# Empty .env file
146212
$ env2json
147-
❌ No .env file found in current directory.
148-
💡 Use --input flag to specify a different .env file:
149-
env2json --input /path/to/.env
150-
env2json --input .env.production
213+
The .env file is empty or contains no valid environment variables.
214+
215+
# Permission denied
216+
$ env2json -input /etc/secrets.env
217+
Error reading .env file: open /etc/secrets.env: permission denied
151218
```
152219

153-
## Build Commands
220+
## Development
221+
222+
### Build Commands
154223

155224
```bash
156225
# Build for current platform
157226
make build
158227

159-
# Build for all platforms
228+
# Build for all platforms
160229
make build-all
161230

162231
# Run tests
163232
make test
164233

165-
# Install locally
234+
# Install locally (OS-specific directory)
166235
make install
167236

168237
# Clean build files
169238
make clean
239+
240+
# Run locally
241+
make run ARGS="-help"
242+
make run ARGS="-input .env.test"
170243
```
171244

172-
## Security Features
245+
### Project Structure
246+
```
247+
env2json/
248+
├── main.go # Main CLI application
249+
├── main_test.go # Unit tests
250+
├── go.mod # Go module definition
251+
├── Makefile # Build automation
252+
├── install.sh # Installation script
253+
├── LICENSE # MIT license
254+
├── README.md # This file
255+
├── .github/workflows/ # GitHub Actions CI/CD
256+
└── build/ # Generated binaries
257+
```
173258

174-
- Automatically detects and masks sensitive environment variables in preview output
175-
- Variables containing keywords like `password`, `secret`, `key`, `token`, etc. are masked as `[MASKED]`
176-
- JSON output contains actual values (needed for secrets managers)
259+
## Security
260+
261+
- **Clean output**: Only outputs JSON, no sensitive data leaked in logs
262+
- **No network calls**: Purely local processing
263+
- **No data storage**: Doesn't save or cache any environment data
264+
- **Clipboard only**: Sensitive data only goes to clipboard (user controlled)
177265

178266
## Supported .env Format
179267

180-
The tool supports standard `.env` file format:
268+
The tool supports standard `.env` file format with robust parsing:
181269

182270
```env
183271
# Comments are ignored
184272
DATABASE_URL=postgresql://user:pass@localhost:5432/mydb
185-
API_KEY=abc123def456
273+
274+
# Quoted values (quotes are automatically removed)
275+
API_KEY="abc123def456"
276+
JWT_SECRET='super-secret-key'
277+
278+
# Unquoted values
186279
PORT=3000
280+
DEBUG=true
187281
188282
# Empty lines are ignored
189-
NODE_ENV=production
283+
284+
# Complex values
285+
REDIS_URL=redis://username:password@redis-server:6379/0
286+
ALLOWED_HOSTS=localhost,127.0.0.1,myapp.com
190287
```
191288

289+
### Parsing Features
290+
-**Comments**: Lines starting with `#` are ignored
291+
-**Empty lines**: Automatically skipped
292+
-**Quoted values**: Single and double quotes removed
293+
-**Complex values**: URLs, comma-separated lists, etc.
294+
-**Whitespace**: Automatically trimmed
295+
-**Invalid lines**: Gracefully skipped
296+
192297
## License
193298

194299
MIT License

0 commit comments

Comments
 (0)