mirror of
https://github.com/kirill-markin/repo-to-text.git
synced 2025-12-06 03:22:23 -08:00
add --create-settings option
This commit is contained in:
parent
6dd163f17e
commit
3513ae7165
2 changed files with 44 additions and 1 deletions
|
|
@ -56,6 +56,14 @@ You can customize the behavior of `repo-to-text` with the following options:
|
|||
|
||||
This will save the file in the specified output directory instead of the current directory.
|
||||
|
||||
- `--create-settings`: Create a default `.repo-to-text-settings.yaml` file with predefined settings. This is useful if you want to start with a template settings file and customize it according to your needs. To create the default settings file, run the following command in your terminal:
|
||||
|
||||
```bash
|
||||
repo-to-text --create-settings
|
||||
```
|
||||
|
||||
This will create a file named `.repo-to-text-settings.yaml` in the current directory. If the file already exists, an error will be raised to prevent overwriting.
|
||||
|
||||
- `--debug`: Enable DEBUG logging. By default, `repo-to-text` runs with INFO logging level. To enable DEBUG logging, use the `--debug` flag:
|
||||
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import logging
|
|||
import argparse
|
||||
import yaml
|
||||
from datetime import datetime
|
||||
import textwrap
|
||||
|
||||
# Importing the missing pathspec module
|
||||
import pathspec
|
||||
|
|
@ -196,15 +197,49 @@ def save_repo_to_text(path='.', output_dir=None) -> str:
|
|||
|
||||
return output_file
|
||||
|
||||
def create_default_settings_file():
|
||||
settings_file = '.repo-to-text-settings.yaml'
|
||||
if os.path.exists(settings_file):
|
||||
raise FileExistsError(f"The settings file '{settings_file}' already exists. Please remove it or rename it if you want to create a new default settings file.")
|
||||
|
||||
default_settings = textwrap.dedent("""\
|
||||
# Details: https://github.com/kirill-markin/repo-to-text
|
||||
# Syntax: gitignore rules
|
||||
|
||||
# Ignore files and directories for all sections from gitignore file
|
||||
# Default: True
|
||||
gitignore-import-and-ignore: True
|
||||
|
||||
# Ignore files and directories for tree
|
||||
# and "Contents of ..." sections
|
||||
ignore-tree-and-content:
|
||||
- ".repo-to-text-settings.yaml"
|
||||
|
||||
# Ignore files and directories for "Contents of ..." section
|
||||
ignore-content:
|
||||
- "README.md"
|
||||
- "LICENSE"
|
||||
""")
|
||||
with open('.repo-to-text-settings.yaml', 'w') as f:
|
||||
f.write(default_settings)
|
||||
print("Default .repo-to-text-settings.yaml created.")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Convert repository structure and contents to text')
|
||||
parser.add_argument('--debug', action='store_true', help='Enable debug logging')
|
||||
parser.add_argument('--output-dir', type=str, help='Directory to save the output file')
|
||||
parser.add_argument('--create-settings', action='store_true', help='Create default .repo-to-text-settings.yaml file') # Новый аргумент
|
||||
args = parser.parse_args()
|
||||
|
||||
setup_logging(debug=args.debug)
|
||||
logging.debug('repo-to-text script started')
|
||||
save_repo_to_text(output_dir=args.output_dir)
|
||||
|
||||
if args.create_settings:
|
||||
create_default_settings_file()
|
||||
logging.debug('.repo-to-text-settings.yaml file created')
|
||||
else:
|
||||
save_repo_to_text(output_dir=args.output_dir)
|
||||
|
||||
logging.debug('repo-to-text script finished')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue