evnx 0.2.0

A comprehensive CLI tool for managing .env files — validation, secret scanning, and format conversion
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
# Getting Started with evnx

**Version:** 0.1.0  
**Last Updated:** February 2026  

Complete guide to using evnx for `.env` file management, validation, and secret scanning.

## Table of Contents

1. [Installation]#installation
2. [Quick Start]#quick-start
3. [Core Commands]#core-commands
4. [Common Use Cases]#common-use-cases
5. [CI/CD Integration]#cicd-integration
6. [Configuration]#configuration
7. [Best Practices]#best-practices
8. [Troubleshooting]#troubleshooting

---

## Installation

### Prerequisites

- Linux, macOS, or WSL2 (Windows support coming soon)
- Rust 1.70+ (for building from source)

### Method 1: Install Script (Recommended)

```bash
curl -sSL https://raw.githubusercontent.com/urwithajit9/evnx/main/install.sh | bash
```

Installs to `/usr/local/bin/evnx`.

### Method 2: Cargo Install

```bash
# Core features only
cargo install evnx

# With all features
cargo install evnx --features full
```

### Method 3: Build from Source

```bash
git clone https://github.com/urwithajit9/evnx.git
cd evnx
cargo build --release --all-features
sudo cp target/release/evnx /usr/local/bin/
```

### Verify Installation

```bash
evnx --version
# Output: evnx 0.1.0

evnx --help
# Shows list of commands
```

---

## Quick Start

### 5-Minute Tutorial

```bash
# 1. Create a new project directory
mkdir my-app && cd my-app

# 2. Initialize with evnx (interactive)
evnx init

# Answer prompts:
# - Stack: python
# - Services: postgres, redis
# - Confirm: yes

# This creates:
# - .env.example (template)
# - .env (copy with placeholder values)
# - .gitignore (adds .env)

# 3. Edit .env with real values
nano .env
# Replace placeholders with actual credentials

# 4. Validate your configuration
evnx validate

# Output:
# ✓ Loaded 8 variables from .env
# ✓ All required variables present
# ✓ No issues found

# 5. Scan for accidentally committed secrets
evnx scan

# Output:
# ✓ Scanned 12 files
# ✓ No secrets detected

# 6. Compare files to see what's different
evnx diff

# Output:
# Missing in .env:
#   - REDIS_URL
# Extra in .env:
#   - DEBUG_MODE

# 7. Convert to different format
evnx convert --to json > config.json

# Done! You now have:
# - Validated configuration
# - Scanned for secrets
# - Multiple format exports
```

---

## Core Commands

### 1. `init` - Project Setup

**Purpose:** Generate `.env.example` with intelligent defaults for your stack.

#### Interactive Mode

```bash
evnx init
```

**Prompts:**
1. Select your stack (Python/Node.js/Rust/Go/PHP)
2. Select services (PostgreSQL/Redis/MongoDB/etc.)
3. Confirm generation

#### Non-Interactive Mode

```bash
# Python with PostgreSQL and Redis
evnx init --stack python --services postgres,redis --yes

# Node.js with MongoDB
evnx init --stack nodejs --services mongodb --yes

# Custom path
evnx init --path backend/.env --yes
```

#### What Gets Generated

**Example for Python + PostgreSQL:**

`.env.example`:
```bash
# Python Application Configuration
PYTHONPATH=.
DEBUG=False

# PostgreSQL Database
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=mydb
SQL_USER=dbuser
SQL_PASSWORD=changeme
SQL_HOST=localhost
SQL_PORT=5432

# Security
SECRET_KEY=your-secret-key-here-minimum-50-characters

# Optional: Redis Cache
# REDIS_URL=redis://localhost:6379/0
```

`.gitignore` (appended):
```bash
# Environment variables
.env
.env.local
```

---

### 2. `validate` - Configuration Validation

**Purpose:** Check `.env` against `.env.example`, catch common mistakes.

#### Basic Validation

```bash
evnx validate
```

**Output (Success):**
```
┌─ Validation Results ─────────────────────────────────┐
│                                                       │
│ ✓ Status: PASSED                                     │
│ ✓ Required variables: 8/8 present                    │
│ ✓ No issues found                                    │
│                                                       │
└───────────────────────────────────────────────────────┘
```

**Output (With Issues):**
```
┌─ Validation Results ─────────────────────────────────┐
│                                                       │
│ ✗ Status: FAILED                                     │
│ ✗ Required variables: 6/8 present                    │
│ ⚠ Issues found: 3                                    │
│                                                       │
└───────────────────────────────────────────────────────┘

❌ Missing Required Variables:
  - DATABASE_URL (line 12 in .env.example)
  - SECRET_KEY (line 18 in .env.example)

⚠️  Warnings:
  - DEBUG="False" (line 3 in .env)
    String "False" is truthy in Python!
    Suggestion: Use DEBUG=0 or DEBUG=false

ℹ️  Summary:
  Errors: 2
  Warnings: 1
  Passed: 6/8 variables
```

#### Strict Mode

```bash
evnx validate --strict
```

Fails on **warnings** too, not just errors. Recommended for CI/CD.

#### Output Formats

**JSON (for parsing):**
```bash
evnx validate --format json
```

```json
{
  "status": "failed",
  "required_present": 6,
  "required_total": 8,
  "issues": [
    {
      "severity": "error",
      "type": "missing_required",
      "variable": "DATABASE_URL",
      "message": "Required variable is missing",
      "location": {
        "file": ".env.example",
        "line": 12
      },
      "suggestion": "Add DATABASE_URL to your .env file"
    }
  ]
}
```

**GitHub Actions (annotations):**
```bash
evnx validate --format github-actions
```

Creates annotations in GitHub Actions UI:
```
::error file=.env,line=1::Missing required variable: DATABASE_URL
::warning file=.env,line=3::DEBUG="False" is truthy in Python
```

#### What Validation Checks

✅ **Missing Required Variables**
```bash
# .env.example has:
DATABASE_URL=...

# .env doesn't have it:
# ❌ ERROR: Missing DATABASE_URL
```

✅ **Placeholder Values**
```bash
# .env has:
API_KEY=YOUR_KEY_HERE
# ❌ ERROR: Placeholder value detected
```

Common placeholders detected:
- `YOUR_KEY_HERE`
- `CHANGE_ME`
- `REPLACE_THIS`
- `EXAMPLE`
- `<insert-...>`
- `TODO`

✅ **Boolean String Trap**
```bash
# Python/Node.js:
DEBUG="False"  # ⚠️  WARNING: String is truthy!
# Should be:
DEBUG=0        # ✅ or false, False (no quotes)
```

✅ **Weak SECRET_KEY**
```bash
SECRET_KEY=123456  # ❌ ERROR: Too short (min 50 chars)
SECRET_KEY=aaaaaaaaaaaaaaaaaaaaaa  # ⚠️  WARNING: Low entropy
```

✅ **localhost in Docker**
```bash
DATABASE_URL=postgresql://localhost:5432/db
# ⚠️  WARNING: localhost won't work in Docker
# Suggestion: Use service name or host.docker.internal
```

✅ **Port Numbers**
```bash
PORT=80   # ⚠️  WARNING: Privileged port, needs root
PORT=99999  # ❌ ERROR: Invalid port (max 65535)
```

---

### 3. `scan` - Secret Detection

**Purpose:** Find accidentally committed credentials in your codebase.

#### Basic Scan

```bash
evnx scan
```

Scans current directory recursively.

**Output (No Secrets):**
```
Scanning directory: .
✓ Scanned 42 files
✓ No secrets detected

Files scanned:
  - .env.example ✓
  - src/*.py ✓
  - tests/*.py ✓
```

**Output (Secrets Found):**
```
⚠️  Found 3 potential secrets:

HIGH CONFIDENCE:
├─ .env:12 - AWS Access Key
│  AKIA4OZRMFJ3EXAMPLE123
│  Pattern: AWS Access Key (AKIA...)
│  ⚠️  Revoke at: https://aws.amazon.com/security/

├─ config.py:45 - Stripe API Key
│  sk_live_51H...
│  Pattern: Stripe Live Key
│  ⚠️  Revoke at: https://dashboard.stripe.com/apikeys

MEDIUM CONFIDENCE:
└─ settings.py:12 - High-entropy string
   a8f3k2j9dks3j2kd9s3jdk29s3jdk2s9
   Entropy: 4.8 bits/char (threshold: 4.5)
   Might be a secret, please verify

Summary:
  High confidence: 2
  Medium confidence: 1
  Files scanned: 42
  
⚠️  Action required: Review and revoke exposed secrets!
```

#### Advanced Scanning

**Scan specific directory:**
```bash
evnx scan --path src/
```

**Exclude files:**
```bash
evnx scan --exclude "*.example" --exclude "*.sample"
```

**Scan for specific patterns:**
```bash
evnx scan --pattern aws --pattern stripe
```

**Ignore obvious placeholders:**
```bash
evnx scan --ignore-placeholders
```

Skips values like:
- `your-key-here`
- `change-me`
- `example-value`

**SARIF output (for GitHub Security):**
```bash
evnx scan --format sarif > scan-results.sarif
```

Upload to GitHub:
```yaml
# .github/workflows/security.yml
- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v2
  with:
    sarif_file: scan-results.sarif
```

#### What Scan Detects

| Pattern | Example | Confidence |
|---------|---------|------------|
| AWS Access Key | `AKIA4OZRMFJ3EXAMPLE123` | High |
| AWS Secret Key | 40-char base64 string | Medium |
| Stripe API Key | `sk_live_...` or `sk_test_...` | High |
| GitHub Token | `ghp_...`, `gho_...`, `ghs_...` | High |
| OpenAI API Key | `sk-...` (48 chars) | High |
| Anthropic API Key | `sk-ant-api...` | High |
| Private Key | `-----BEGIN PRIVATE KEY-----` | High |
| Generic API Key | `api_key=...` (32+ chars) | Medium |
| High Entropy | Random-looking strings | Low |

---

### 4. `diff` - File Comparison

**Purpose:** See differences between `.env` and `.env.example`.

#### Basic Diff

```bash
evnx diff
```

**Output:**
```
┌─ Comparing .env vs .env.example ─────────────────────┐

Missing in .env (required):
  ├─ DATABASE_URL
  ├─ REDIS_URL
  └─ SECRET_KEY

Extra in .env (not in example):
  ├─ DEBUG_MODE
  └─ LOCAL_SETTING

Different values:
  PORT: 8000 → 3000

Summary:
  Missing: 3
  Extra: 2
  Different: 1
  
└───────────────────────────────────────────────────────┘
```

#### Show Actual Values

```bash
evnx diff --show-values
```

```
Missing in .env:
  DATABASE_URL = postgresql://localhost:5432/db

Extra in .env:
  DEBUG_MODE = true
  LOCAL_SETTING = /tmp/data

Different values:
  PORT: 8000 → 3000
```

⚠️  **Security:** By default, values are hidden to prevent accidental exposure.

#### Reverse Comparison

```bash
evnx diff --reverse
```

Compares `.env.example` vs `.env` (swap direction).

#### JSON Output

```bash
evnx diff --format json
```

```json
{
  "missing": ["DATABASE_URL", "REDIS_URL"],
  "extra": ["DEBUG_MODE"],
  "different": [
    {
      "key": "PORT",
      "env_value": "8000",
      "example_value": "3000"
    }
  ]
}
```

---

### 5. `convert` - Format Conversion

**Purpose:** Transform `.env` to 14+ different formats.

#### Basic Conversion

```bash
# JSON
evnx convert --to json

# YAML
evnx convert --to yaml

# Shell script
evnx convert --to shell
```

#### Save to File

```bash
evnx convert --to json --output config.json
```

#### Filter Variables

**Include specific variables:**
```bash
evnx convert --to json --include "AWS_*"
```

Only exports variables starting with `AWS_`.

**Exclude variables:**
```bash
evnx convert --to json --exclude "*_LOCAL"
```

Skips variables ending with `_LOCAL`.

#### Transform Keys

```bash
# Uppercase
evnx convert --to json --transform uppercase

# Lowercase
evnx convert --to json --transform lowercase

# camelCase
evnx convert --to json --transform camelCase

# snake_case
evnx convert --to json --transform snake_case
```

**Example:**
```bash
# Input: database_url=...
# uppercase: DATABASE_URL
# lowercase: database_url
# camelCase: databaseUrl
# snake_case: database_url
```

#### Add Prefix

```bash
evnx convert --to json --prefix "APP_"
```

```json
{
  "APP_DATABASE_URL": "...",
  "APP_SECRET_KEY": "...",
  "APP_PORT": "8000"
}
```

#### Base64 Encode

```bash
evnx convert --to kubernetes --base64
```

Useful for Kubernetes Secrets (must be base64-encoded).

#### All Formats

**Generic formats:**
- `json` - Simple JSON object
- `yaml` - YAML format
- `shell` - Shell export script

**Cloud providers:**
- `aws-secrets` - AWS Secrets Manager (CLI commands)
- `gcp-secrets` - GCP Secret Manager (gcloud commands)
- `azure-keyvault` - Azure Key Vault (az commands)

**CI/CD:**
- `github-actions` - GitHub Actions secrets format
- `gitlab-ci` - GitLab CI variables

**Containers:**
- `docker-compose` - Docker Compose env_file format
- `kubernetes` - Kubernetes Secret YAML

**Infrastructure:**
- `terraform` - Terraform .tfvars file

**Secret managers:**
- `doppler` - Doppler secrets JSON
- `heroku` - Heroku config vars (heroku commands)
- `vercel` - Vercel environment variables JSON
- `railway` - Railway JSON format

---

### 6. `sync` - Bidirectional Sync

**Purpose:** Keep `.env` and `.env.example` in sync.

#### Forward Sync (.env → .env.example)

**Use case:** You added variables to `.env`, now document them in `.env.example`.

```bash
evnx sync --direction forward --placeholder
```

**What it does:**
1. Reads all variables from `.env`
2. Adds missing ones to `.env.example`
3. Uses placeholder values (not real secrets!)

**Example:**
```bash
# .env has:
DATABASE_URL=postgresql://prod-db:5432/app
NEW_FEATURE_FLAG=enabled

# After sync, .env.example has:
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
NEW_FEATURE_FLAG=your-value-here
```

#### Reverse Sync (.env.example → .env)

**Use case:** Generate `.env` from template in CI/CD.

```bash
evnx sync --direction reverse
```

**What it does:**
1. Reads template from `.env.example`
2. Creates/updates `.env`
3. Fills values from environment variables

**Example CI/CD usage:**
```bash
# GitLab CI variables:
export DATABASE_URL="postgresql://ci-db:5432/test"
export SECRET_KEY="ci-secret-key"

# Generate .env for this run
evnx sync --direction reverse

# Now .env has:
# DATABASE_URL=postgresql://ci-db:5432/test
# SECRET_KEY=ci-secret-key
```

---

## Common Use Cases

### Use Case 1: New Python Project Setup

```bash
# 1. Initialize project
mkdir my-django-app && cd my-django-app
evnx init --stack python --services postgres,redis

# 2. Edit .env with real values
nano .env

# 3. Validate before first run
evnx validate --strict

# 4. Add to git
git add .env.example .gitignore
git commit -m "Add environment configuration"
# Note: .env is NOT committed (in .gitignore)

# 5. Other developers clone and run:
evnx validate  # Shows what's missing
# Then they fill in their own .env
```

---

### Use Case 2: Pre-commit Secret Scanning

**Goal:** Prevent accidental secret commits.

**Setup:**
```bash
# Install pre-commit
pip install pre-commit

# Create .pre-commit-config.yaml
cat > .pre-commit-config.yaml << 'EOF'
repos:
  - repo: local
    hooks:
      - id: dotenv-scan
        name: Scan for secrets
        entry: evnx scan --exit-zero
        language: system
        pass_filenames: false
        stages: [commit]
EOF

# Install hook
pre-commit install
```

**Now every commit:**
```bash
git add .
git commit -m "Update config"

# Pre-commit runs:
# Scanning for secrets...
# ⚠️  Found AWS Access Key in .env
# Commit blocked!
```

---

### Use Case 3: CI/CD Validation

**GitHub Actions:**

```yaml
# .github/workflows/validate.yml
name: Validate Environment

on: [push, pull_request]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install evnx
        run: |
          curl -sSL https://install.dotenv.space | bash
          echo "$HOME/.local/bin" >> $GITHUB_PATH
      
      - name: Validate
        run: evnx validate --strict --format github-actions
      
      - name: Scan for secrets
        run: evnx scan --format sarif > scan.sarif
      
      - name: Upload SARIF
        uses: github/codeql-action/upload-sarif@v2
        if: always()
        with:
          sarif_file: scan.sarif
```

**Result:**
- ✅ Validation errors appear as annotations
- ✅ Secrets appear in Security tab
- ✅ PR blocked if validation fails

---

### Use Case 4: Docker Deployment

**Problem:** Need to pass environment variables to Docker container.

**Solution 1: Docker Compose format**

```bash
evnx convert --to docker-compose > .env.docker

docker-compose --env-file .env.docker up
```

**Solution 2: Kubernetes Secret**

```bash
evnx convert --to kubernetes --base64 > secret.yaml

kubectl apply -f secret.yaml
```

**Solution 3: AWS ECS Task Definition**

```bash
evnx convert --to json | \
  aws ecs register-task-definition \
    --family my-app \
    --container-definitions file:///dev/stdin
```

---

### Use Case 5: Multi-Environment Management

**Setup:**
```bash
my-app/
├── .env.development
├── .env.staging
├── .env.production
└── .env.example
```

**Validate all environments:**
```bash
for env in development staging production; do
  echo "Validating $env..."
  evnx validate \
    --env .env.$env \
    --example .env.example \
    --strict
done
```

**Convert for deployment:**
```bash
# Staging
evnx convert \
  --env .env.staging \
  --to aws-secrets \
  --output staging-secrets.sh

# Production
evnx convert \
  --env .env.production \
  --to aws-secrets \
  --output prod-secrets.sh
```

---

## CI/CD Integration

### GitHub Actions

**Complete workflow:**

```yaml
name: Environment Validation

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  validate-env:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install evnx
        run: |
          curl -sSL https://raw.githubusercontent.com/urwithajit9/evnx/main/install.sh | bash
          echo "$HOME/.local/bin" >> $GITHUB_PATH
      
      - name: Validate configuration
        run: |
          evnx validate \
            --strict \
            --format github-actions
      
      - name: Scan for secrets
        run: |
          evnx scan \
            --format sarif \
            --ignore-placeholders > scan-results.sarif
      
      - name: Upload SARIF to GitHub Security
        uses: github/codeql-action/upload-sarif@v2
        if: always()
        with:
          sarif_file: scan-results.sarif
      
      - name: Compare with example
        run: |
          evnx diff --format json > diff-report.json
      
      - name: Upload diff report
        uses: actions/upload-artifact@v3
        with:
          name: env-diff-report
          path: diff-report.json
```

---

### GitLab CI

```yaml
# .gitlab-ci.yml
stages:
  - validate
  - test
  - deploy

validate-env:
  stage: validate
  image: alpine:latest
  before_script:
    - apk add --no-cache curl bash
    - curl -sSL https://install.dotenv.space | bash
  script:
    - evnx validate --strict --format json
    - evnx scan --format sarif > gl-sast-report.json
  artifacts:
    reports:
      sast: gl-sast-report.json
  only:
    - merge_requests
    - main

test:
  stage: test
  before_script:
    - evnx sync --direction reverse
    - evnx validate --strict
  script:
    - npm test

deploy-staging:
  stage: deploy
  before_script:
    - evnx convert --to aws-secrets > setup-secrets.sh
  script:
    - bash setup-secrets.sh
    - ./deploy.sh staging
  only:
    - develop
```

---

### Jenkins

```groovy
pipeline {
    agent any
    
    stages {
        stage('Install evnx') {
            steps {
                sh 'curl -sSL https://install.dotenv.space | bash'
            }
        }
        
        stage('Validate') {
            steps {
                sh 'evnx validate --strict'
            }
        }
        
        stage('Scan') {
            steps {
                sh 'evnx scan --format json > scan-results.json'
                archiveArtifacts artifacts: 'scan-results.json'
            }
        }
        
        stage('Deploy') {
            when {
                branch 'main'
            }
            steps {
                sh '''
                    evnx convert --to aws-secrets | \
                    aws secretsmanager create-secret \
                      --name prod/myapp/config \
                      --secret-string file:///dev/stdin
                '''
            }
        }
    }
}
```

---

## Configuration

### Config File: `.evnx.toml`

Place in project root or home directory:

```toml
[defaults]
env_file = ".env"
example_file = ".env.example"
verbose = false

[validate]
strict = true
auto_fix = false
format = "pretty"

[scan]
ignore_placeholders = true
exclude_patterns = ["*.example", "*.sample", "*.template", "test_*.env"]
format = "pretty"

[convert]
default_format = "json"
base64 = false
# prefix = "APP_"
# transform = "uppercase"

[aliases]
# Shortcuts for convert command
gh = "github-actions"
k8s = "kubernetes"
tf = "terraform"
aws = "aws-secrets"
```

**Using aliases:**
```bash
evnx convert --to gh    # Same as --to github-actions
evnx convert --to k8s   # Same as --to kubernetes
```

---

## Best Practices

### 1. Never Commit `.env`

**✅ Do:**
```bash
# .gitignore
.env
.env.local
.env.*.local
```

**❌ Don't:**
```bash
git add .env  # NEVER!
```

### 2. Always Commit `.env.example`

```bash
git add .env.example
git commit -m "Update environment template"
```

### 3. Use Strict Validation in CI

```yaml
# GitHub Actions
- run: evnx validate --strict --format github-actions
```

### 4. Scan Before Every Commit

```bash
# .pre-commit-config.yaml
- id: dotenv-scan
  entry: evnx scan --exit-zero
```

### 5. Use Descriptive Comments

```bash
# .env.example

# Database connection string
# Format: postgresql://user:password@host:port/database
# Required: Yes
DATABASE_URL=postgresql://localhost:5432/mydb

# Secret key for session signing
# Generate: python -c 'import secrets; print(secrets.token_hex(32))'
# Required: Yes
# Minimum length: 32 characters
SECRET_KEY=your-secret-key-here
```

### 6. Rotate Secrets Regularly

```bash
# Check secret age
evnx scan --format json | jq '.findings[] | select(.age_days > 90)'

# Generate new secrets
python -c 'import secrets; print(secrets.token_urlsafe(32))'
```

### 7. Use Secret Managers in Production

```bash
# Don't use .env files in production
# Migrate to secret manager:

evnx convert --to aws-secrets | \
  aws secretsmanager create-secret \
    --name prod/myapp/config \
    --secret-string file:///dev/stdin

# Or use migrate command (with --features migrate):
evnx migrate \
  --to aws-secrets-manager \
  --secret-name prod/myapp/config
```

---

## Troubleshooting

### Problem: "Command not found: evnx"

**Solution:**
```bash
# Add to PATH
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

# Or reinstall
curl -sSL https://install.dotenv.space | bash
```

### Problem: "Missing required variable" but it exists

**Cause:** Variable has different name or whitespace.

**Solution:**
```bash
# Show exact names
evnx diff --show-values

# Common issues:
DATABASE_URL  # ✅ Correct
DATABASE URL  # ❌ Space in name
DATABASE_URL= # ❌ Trailing space
```

### Problem: Validation passes but app crashes

**Cause:** Variable exists but has wrong format/value.

**Solution:**
Add format validation to `.env.example`:
```bash
# Add comments describing expected format
# DATABASE_URL format: postgresql://user:pass@host:port/db
DATABASE_URL=postgresql://localhost:5432/mydb

# PORT must be integer 1-65535
PORT=8000
```

Then use `evnx validate --strict`.

### Problem: "Permission denied" when running

**Solution:**
```bash
chmod +x ~/.local/bin/evnx
```

### Problem: Too many warnings

**Solution:**
Use config file to customize:

```toml
# .evnx.toml
[scan]
ignore_placeholders = true
exclude_patterns = ["*.example", "*.test"]
```

---

## Next Steps

- **[Use Cases]./USE_CASES.md** - Real-world scenarios
- **[CI/CD Guide]./CICD_GUIDE.md** - Detailed CI/CD integration
- **[Architecture]../ARCHITECTURE.md** - How it works internally
- **[Contributing]../CONTRIBUTING.md** - Help improve evnx

---

## Get Help

- 🐛 [Report a bug]https://github.com/urwithajit9/evnx/issues
- 💡 [Request a feature]https://github.com/urwithajit9/evnx/issues
- 💬 [Ask a question]https://github.com/urwithajit9/evnx/discussions

---

**Happy environment managing! 🚀**