Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Struct devcontainer",
"image": "mcr.microsoft.com/devcontainers/python:3",
"features": {
"ghcr.io/devcontainers/features/python:1": {},
// "ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/gvatsal60/dev-container-features/pre-commit:1": {}
},
"postCreateCommand": "bash ./scripts/devcontainer_start.sh",
Expand Down Expand Up @@ -30,5 +30,9 @@
"mounts": [
"type=bind,source=${localWorkspaceFolder},target=/work",
"type=bind,source=/home/${localEnv:USER}/.ssh,target=/home/vscode/.ssh"
]
],
// environment variables to be set in the container
"remoteEnv": {
"OPENAI_API_KEY": "set-key-here"
}
}
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ When defining your project structure in the YAML configuration file, you can use
- **content**: Define the content of the file directly in the YAML configuration.
- **file**: Specify a local or remote file to include. Supported protocols include `file://`, `http://`, `https://`, `github://`, `githubhttps://`, `githubssh://`, `s3://`, and `gs://`.

> **Note**: For local `.yaml` files, the `file://` protocol is automatically added if not specified.

Example:

```yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pytest tests/integration/
### Enable Debug Logging

```sh
struct --log=DEBUG generate file://my-config.yaml ./output
struct --log=DEBUG generate my-config.yaml ./output
```

### Use Python Debugger
Expand Down
8 changes: 5 additions & 3 deletions docs/file-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ Control how STRUCT handles existing files with the `--file-strategy` option:

```sh
# Skip existing files
struct generate --file-strategy=skip file://my-config.yaml ./output
struct generate --file-strategy=skip my-config.yaml ./output

# Backup existing files
struct generate --file-strategy=backup --backup=/tmp/backup file://my-config.yaml ./output
struct generate --file-strategy=backup --backup=/tmp/backup my-config.yaml ./output

# Rename existing files
struct generate --file-strategy=rename file://my-config.yaml ./output
struct generate --file-strategy=rename my-config.yaml ./output
```

> **Note**: The `file://` protocol is automatically added for `.yaml` files, so these examples work with or without the explicit protocol.

## Advanced Examples

### Conditional File Creation
Expand Down
6 changes: 4 additions & 2 deletions docs/mappings.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ This approach allows you to pass specific mapping values as variables to nested
Use the `--mappings-file` argument with the `generate` command:

```sh
# Both commands work identically - file:// is automatically added for .yaml files
struct generate --mappings-file ./mymap.yaml my-struct.yaml .
struct generate --mappings-file ./mymap.yaml file://my-struct.yaml .
```

Expand All @@ -157,7 +159,7 @@ You can specify multiple mappings files that will be merged in order:
struct generate \
--mappings-file ./common-mappings.yaml \
--mappings-file ./env-specific-mappings.yaml \
file://my-struct.yaml .
my-struct.yaml .
```

**Merging behavior:**
Expand All @@ -173,7 +175,7 @@ struct generate \
struct generate \
--mappings-file ./mappings/common.yaml \
--mappings-file ./mappings/${ENVIRONMENT}.yaml \
file://infrastructure.yaml \
infrastructure.yaml \
./output
```

Expand Down
4 changes: 3 additions & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ mkdir example
cd example/
touch structure.yaml
vim structure.yaml # copy the content from the example folder
struct generate file://structure.yaml .
struct generate structure.yaml .
```

> **Note**: The `file://` protocol is automatically added for `.yaml` files, so `structure.yaml` and `file://structure.yaml` work identically.

## First Example

After installing STRUCT, try this simple example:
Expand Down
10 changes: 10 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ struct -h
struct generate terraform-module ./my-terraform-module
```

### YAML File Usage

For local YAML configuration files, the `file://` protocol is automatically added:

```sh
# Both of these work identically
struct generate my-config.yaml ./output
struct generate file://my-config.yaml ./output
```

### Complete Example

```sh
Expand Down
3 changes: 3 additions & 0 deletions struct_module/commands/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def _run_hooks(self, hooks, hook_type="pre"): # helper for running hooks
return True

def _load_yaml_config(self, structure_definition, structures_path):
if structure_definition.endswith(".yaml") and not structure_definition.startswith("file://"):
structure_definition = f"file://{structure_definition}"

if structure_definition.startswith("file://") and structure_definition.endswith(".yaml"):
with open(structure_definition[7:], 'r') as f:
return yaml.safe_load(f)
Expand Down
Loading