generate-env-sample 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: generate-env-sample
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author: Heshinth P
|
|
6
|
+
Author-email: heshinth@gmail.com
|
|
7
|
+
Requires-Dist: typer-slim>=0.17.4
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Project-URL: Issues, https://github.com/heshinth/generate-env-sample/issues
|
|
10
|
+
Project-URL: Repository, https://github.com/heshinth/generate-env-sample.git
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# generate-env-sample
|
|
14
|
+
|
|
15
|
+
A simple CLI tool to generate `.env.sample` files from existing `.env` files. This tool reads your `.env` file, preserves comments and empty lines, and creates a sample file with keys but without values.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- Preserves comments and empty lines from the original `.env` file.
|
|
20
|
+
- Generates a clean `.env.sample` with keys set to empty values.
|
|
21
|
+
- Built with Python and Typer.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Prerequisites
|
|
27
|
+
- Python 3.11 or higher
|
|
28
|
+
|
|
29
|
+
### Install from Source
|
|
30
|
+
1. Clone the repository:
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/heshinth/generate-env-sample.git
|
|
33
|
+
cd generate-env-sample
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
2. Install dependencies using `uv` (recommended):
|
|
37
|
+
```bash
|
|
38
|
+
uv sync
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or using pip:
|
|
42
|
+
```bash
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
Run the tool from the command line:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
generate-env-sample
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Options
|
|
55
|
+
- `--file-name`: Specify the `.env` file to read from (default: `.env`)
|
|
56
|
+
- `--sample-name`: Specify the output `.env.sample` file (default: `.env.sample`)
|
|
57
|
+
|
|
58
|
+
### Examples
|
|
59
|
+
|
|
60
|
+
1. Generate `.env.sample` from the default `.env`:
|
|
61
|
+
```bash
|
|
62
|
+
generate-env-sample
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. Use a custom `.env` file:
|
|
66
|
+
```bash
|
|
67
|
+
generate-env-sample --file-name myenv.env --sample-name myenv.sample
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
3. Get help:
|
|
71
|
+
```bash
|
|
72
|
+
generate-env-sample --help
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Example Input/Output
|
|
76
|
+
|
|
77
|
+
Given a `.env` file like:
|
|
78
|
+
```
|
|
79
|
+
# Database configuration
|
|
80
|
+
DB_HOST=localhost
|
|
81
|
+
DB_PORT=5432
|
|
82
|
+
|
|
83
|
+
# API keys
|
|
84
|
+
API_KEY=your_secret_key
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The generated `.env.sample` will be:
|
|
88
|
+
```
|
|
89
|
+
# Database configuration
|
|
90
|
+
DB_HOST=
|
|
91
|
+
DB_PORT=
|
|
92
|
+
|
|
93
|
+
# API keys
|
|
94
|
+
API_KEY=
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Contributing
|
|
98
|
+
|
|
99
|
+
Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/heshinth/generate-env-sample).
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# generate-env-sample
|
|
2
|
+
|
|
3
|
+
A simple CLI tool to generate `.env.sample` files from existing `.env` files. This tool reads your `.env` file, preserves comments and empty lines, and creates a sample file with keys but without values.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Preserves comments and empty lines from the original `.env` file.
|
|
8
|
+
- Generates a clean `.env.sample` with keys set to empty values.
|
|
9
|
+
- Built with Python and Typer.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Prerequisites
|
|
15
|
+
- Python 3.11 or higher
|
|
16
|
+
|
|
17
|
+
### Install from Source
|
|
18
|
+
1. Clone the repository:
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/heshinth/generate-env-sample.git
|
|
21
|
+
cd generate-env-sample
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
2. Install dependencies using `uv` (recommended):
|
|
25
|
+
```bash
|
|
26
|
+
uv sync
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or using pip:
|
|
30
|
+
```bash
|
|
31
|
+
pip install -e .
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Run the tool from the command line:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
generate-env-sample
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Options
|
|
43
|
+
- `--file-name`: Specify the `.env` file to read from (default: `.env`)
|
|
44
|
+
- `--sample-name`: Specify the output `.env.sample` file (default: `.env.sample`)
|
|
45
|
+
|
|
46
|
+
### Examples
|
|
47
|
+
|
|
48
|
+
1. Generate `.env.sample` from the default `.env`:
|
|
49
|
+
```bash
|
|
50
|
+
generate-env-sample
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
2. Use a custom `.env` file:
|
|
54
|
+
```bash
|
|
55
|
+
generate-env-sample --file-name myenv.env --sample-name myenv.sample
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
3. Get help:
|
|
59
|
+
```bash
|
|
60
|
+
generate-env-sample --help
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Example Input/Output
|
|
64
|
+
|
|
65
|
+
Given a `.env` file like:
|
|
66
|
+
```
|
|
67
|
+
# Database configuration
|
|
68
|
+
DB_HOST=localhost
|
|
69
|
+
DB_PORT=5432
|
|
70
|
+
|
|
71
|
+
# API keys
|
|
72
|
+
API_KEY=your_secret_key
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The generated `.env.sample` will be:
|
|
76
|
+
```
|
|
77
|
+
# Database configuration
|
|
78
|
+
DB_HOST=
|
|
79
|
+
DB_PORT=
|
|
80
|
+
|
|
81
|
+
# API keys
|
|
82
|
+
API_KEY=
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Contributing
|
|
86
|
+
|
|
87
|
+
Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/heshinth/generate-env-sample).
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "generate-env-sample"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{name = "Heshinth P"},
|
|
8
|
+
{email = "heshinth@gmail.com"}
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
dependencies = ["typer-slim>=0.17.4"]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Repository = "https://github.com/heshinth/generate-env-sample.git"
|
|
16
|
+
Issues = "https://github.com/heshinth/generate-env-sample/issues"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
generate-env-sample = "generate_env_sample.main:app"
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["uv_build>=0.8.14,<0.9.0"]
|
|
24
|
+
build-backend = "uv_build"
|
|
File without changes
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing_extensions import Annotated
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
app = typer.Typer(
|
|
7
|
+
add_completion=False,
|
|
8
|
+
help="A CLI tool to generate .env.sample files from .env files.",
|
|
9
|
+
invoke_without_command=True,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@app.command()
|
|
14
|
+
def main(
|
|
15
|
+
file: Annotated[str, typer.Option(help="The .env file to read from")] = ".env",
|
|
16
|
+
sample: Annotated[
|
|
17
|
+
str, typer.Option(help="The .env.sample file to create")
|
|
18
|
+
] = ".env.sample",
|
|
19
|
+
) -> None:
|
|
20
|
+
"""
|
|
21
|
+
Generate a .env.sample file from the existing .env file.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
env_path = Path(file)
|
|
25
|
+
sample_path = Path(sample)
|
|
26
|
+
|
|
27
|
+
if not env_path.exists():
|
|
28
|
+
typer.echo(f"Error: {file} file not found.", err=True)
|
|
29
|
+
raise typer.Exit(code=1)
|
|
30
|
+
|
|
31
|
+
if sample_path.exists():
|
|
32
|
+
overwrite = typer.confirm(
|
|
33
|
+
f"File {sample} already exists. Overwrite?", default=True
|
|
34
|
+
)
|
|
35
|
+
if not overwrite:
|
|
36
|
+
typer.echo("Operation cancelled.")
|
|
37
|
+
raise typer.Exit(code=0)
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
with env_path.open("r", encoding="utf-8") as env_file:
|
|
41
|
+
typer.echo(f"Generating {sample} from {file}...")
|
|
42
|
+
sample_lines = []
|
|
43
|
+
|
|
44
|
+
for line in env_file:
|
|
45
|
+
stripped = line.strip()
|
|
46
|
+
if not stripped or stripped.startswith("#"):
|
|
47
|
+
sample_lines.append(line) # Preserve comments and empty lines
|
|
48
|
+
elif "=" in line:
|
|
49
|
+
key = line.split("=", 1)[0].strip()
|
|
50
|
+
sample_lines.append(f"{key}=\n")
|
|
51
|
+
else:
|
|
52
|
+
# Treat non-key lines as comments or skip
|
|
53
|
+
sample_lines.append(line)
|
|
54
|
+
|
|
55
|
+
with sample_path.open("w", encoding="utf-8") as sample_file:
|
|
56
|
+
sample_file.writelines(sample_lines)
|
|
57
|
+
|
|
58
|
+
typer.echo(f"{sample} created successfully!")
|
|
59
|
+
|
|
60
|
+
except PermissionError:
|
|
61
|
+
typer.echo(
|
|
62
|
+
f"Error: Permission denied for {file} or {sample}.", err=True
|
|
63
|
+
)
|
|
64
|
+
raise typer.Exit(code=1)
|
|
65
|
+
|
|
66
|
+
except UnicodeDecodeError:
|
|
67
|
+
typer.echo(
|
|
68
|
+
f"Error: Encoding issue with {file}. Ensure it's UTF-8.", err=True
|
|
69
|
+
)
|
|
70
|
+
raise typer.Exit(code=1)
|
|
71
|
+
|
|
72
|
+
except Exception as e:
|
|
73
|
+
typer.echo(f"An unexpected error occurred: {e}", err=True)
|
|
74
|
+
raise typer.Exit(code=1)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
app()
|