-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md.old
242 lines (164 loc) · 5.68 KB
/
README.md.old
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
# 📒 Project Structure Generator
## Overview
A library and command-line tool for getting directory structures in different formats. This tool allows you to inspect a directory and create a structured representation of its contents in JSON, YAML, or plain text. You can also pretty-print the structure with colorful output.
## Features
✅ Generate directory structures in JSON, YAML, or plain text formats.
📝 Read patterns from a `.gitignore` file to exclude specific files or directories.
🎨 Pretty-print the directory structure with colorful output.
📦 Easily configurable and customizable.
## Installation
(still not installable 🛠)
To install the package, you can use `pip`:
```
pip install pstruc
```
## CLI Usage
### Basic Usage
Generate a directory structure and save it to a YAML file:
```
python pstruc.py /path/to/directory -f yaml -o output_structure
```
Pretty-print the directory structure:
```
python pstruc.py /path/to/directory -p
```
### Advanced Usage
Use the `.gitignore` file to specify patterns to exclude:
```
# .gitignore
# Exclude virtual environment, cache, and log files
.env
__pycache__
*.log
```
Exclude patterns specified in `.gitignore` when generating the structure:
```
python pstruc.py /path/to/directory -f json
```
Include content of specified files (code, readmes, etc):
```
python pstruc.py /path/to/directory -f [format] -fc [content file patterns]
```
Do not save the generated structure to an output file:
```
python pstruc.py /path/to/directory -ns
```
Add custom patterns to ignore in addition to .gitignore:
```
python pstruc.py /path/to/directory -ip "pattern1,pattern2"
```
For more options and details, run:
```
python pstruc.py --help
```
## Example
Suppose you have the following directory structure:
```
my_project/
├── documents/
│ ├── report.txt
│ ├── proposal.docx
│ └── presentation.pptx
├── source_code/
│ ├── main.py
│ ├── utils/
│ │ ├── helper.py
│ │ └── constants.py
│ └── tests/
│ ├── test_main.py
│ └── test_utils.py
└── README.md
```
Running the following command:
```
python pstruc.py my_project -f json
```
Will generate a JSON representation of the directory structure.
```json
{
"my_project": {
"documents": {
"report.txt": null,
"proposal.docx": null,
"presentation.pptx": null
},
"source_code": {
"main.py": null,
"utils": {
"helper.py": null,
"constants.py": null
},
"tests": {
"test_main.py": null,
"test_utils.py": null
}
},
"README.md": null
}
}
```
## 📚 Library Usage
In addition to being a command-line tool, `pstruc` can also be used as a library in your own Python projects. This allows you to integrate directory structure generation and manipulation directly into your scripts or applications.
### 🔧 Available Functions
The `pstruc` library offers the following key functions for use in your projects:
#### 🔍 `get_project_structure`
Generates a directory structure for a specified directory.
**Parameters:**
- `start_path (str)`: The directory to inspect.
- `output_format (str)`: The desired output format ('json', 'yaml', or 'txt').
- `ignore_patterns (list)`: List of additional patterns to ignore.
- `file_content (list)`: List of patterns to determine which file content to include in the structure.
**Returns:**
- `str`: The directory structure in the specified format.
**Example:**
```python
from pstruc import get_project_structure
structure = get_project_structure('/path/to/directory', 'json')
print(structure)
```
#### 💾 `save_structure_to_file`
Saves the directory structure to a file.
**Parameters:**
- `output_file (str)`: The name of the output file.
- `structure (str)`: The directory structure content to be saved.
**Returns:**
- `None` or `str`: An error message if an error occurs; otherwise, `None`.
**Example:**
```python
from pstruc import save_structure_to_file
error = save_structure_to_file('output.json', structure)
if error:
print(f"Error saving file: {error}")
```
#### 🎨 `pretty_print`
Pretty-prints a directory structure.
**Parameters:**
- `structure (str or dict)`: The directory structure to print.
- `indentation (str)`: The current indentation level.
**Example:**
```python
from pstruc import pretty_print
pretty_print(structure)
```
### ⚙️ Advanced Integration
You can integrate these functions into your Python applications to dynamically generate, save, and display directory structures. This is particularly useful for building tools that require a clear understanding of project layouts or for automating documentation tasks.
## Documentation
For detailed documentation and examples, please refer to the [Wiki](https://github.com/nachokhan/pstruc/wiki).
## Contributing
Contributions are welcome! If you want to contribute to this project, please follow the [Contributing Guidelines](CONTRIBUTING.md).
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- [colorama](https://pypi.org/project/colorama/) - For colorful output.
## Contact
👤 Ignacio Rigoni
- GitHub: [https://github.com/nachokhan](https://github.com/nachokhan)
- Email: [email protected]
## Support
If you encounter any issues or have questions, please [open an issue](https://github.com/nachokhan/pstruc/issues).
## Roadmap
See the [open issues](https://github.com/nachokhan/pstruc/issues) for a list of proposed features and known issues.
## Changelog
See the [CHANGELOG](CHANGELOG.md) for a list of changes in each version of the project.
## Credits
- Icons by [FontAwesome](https://fontawesome.com/)