Skip to content

Commit 19bb0c5

Browse files
authored
feat(generate): default structure_definition and base_path when omitted (#114)
Summary This PR improves the UX of the generate command by making both positional arguments optional with sensible defaults. Users can now run struct generate with no additional arguments when a .struct.yaml is present in the current directory. Motivation - Streamline the most common workflow: running generation from the current directory using a local .struct.yaml. - Reduce friction and boilerplate for quick iterations and demos. Changes - CLI: Make positional args optional in GenerateCommand - structure_definition defaults to .struct.yaml - base_path defaults to . - Explicitly provided arguments continue to override these defaults. - Docs: Updated to reflect new defaults - docs/cli-reference.md - docs/usage.md - docs/quickstart.md Usage ```sh # With defaults (if .struct.yaml exists in the current directory) struct generate # From a specific YAML file into a target directory (unchanged) struct generate file://my-config.yaml ./output # Using a built-in structure definition into a directory (unchanged) struct generate python-basic ./my-project ``` Backward compatibility - Existing commands remain valid; this is an additive improvement. - Explicit arguments still take precedence over defaults. Testing - Full test suite executed locally: 112 tests passed. - No behavior changes to existing flows other than allowing omitted positional args with sensible defaults. Docs - CLI reference updated to show optional positional args and defaults. - Usage and Quickstart updated with examples using struct generate without arguments. Closes #113.
1 parent 3464fbf commit 19bb0c5

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

docs/cli-reference.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,22 @@ Generate the project structure.
5959
**Usage:**
6060

6161
```sh
62-
struct generate [-h] [-l LOG] [-c CONFIG_FILE] [-i LOG_FILE] [-s STRUCTURES_PATH] [-n INPUT_STORE] [-d] [--diff] [-v VARS] [-b BACKUP] [-f {overwrite,skip,append,rename,backup}] [-p GLOBAL_SYSTEM_PROMPT] [--non-interactive] [--mappings-file MAPPINGS_FILE] [-o {console,file}] structure_definition base_path
62+
struct generate [-h] [-l LOG] [-c CONFIG_FILE] [-i LOG_FILE] [-s STRUCTURES_PATH] [-n INPUT_STORE] [-d] [--diff] [-v VARS] [-b BACKUP] [-f {overwrite,skip,append,rename,backup}] [-p GLOBAL_SYSTEM_PROMPT] [--non-interactive] [--mappings-file MAPPINGS_FILE] [-o {console,file}] [structure_definition] [base_path]
63+
```
64+
65+
Defaults when omitted:
66+
- structure_definition -> .struct.yaml
67+
- base_path -> .
68+
69+
Example:
70+
```sh
71+
struct generate
6372
```
6473

6574
**Arguments:**
6675

67-
- `structure_definition`: Path to the YAML configuration file.
68-
- `base_path`: Base path where the structure will be created.
76+
- `structure_definition` (optional): Path to the YAML configuration file (default: `.struct.yaml`).
77+
- `base_path` (optional): Base path where the structure will be created (default: `.`).
6978
- `-s STRUCTURES_PATH, --structures-path STRUCTURES_PATH`: Path to structure definitions.
7079
- `-n INPUT_STORE, --input-store INPUT_STORE`: Path to the input store.
7180
- `-d, --dry-run`: Perform a dry run without creating any files or directories.
@@ -139,6 +148,14 @@ struct init [path]
139148

140149
## Examples
141150

151+
### Using Defaults
152+
153+
Generate with default structure (.struct.yaml) into current directory:
154+
155+
```sh
156+
struct generate
157+
```
158+
142159
### Basic Structure Generation
143160

144161
Generate a structure using a built-in definition:

docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ vim structure.yaml # copy the content from the example folder
4343
struct generate structure.yaml .
4444
```
4545

46-
> **Note**: The `file://` protocol is automatically added for `.yaml` files, so `structure.yaml` and `file://structure.yaml` work identically.
46+
> Note: The `file://` protocol is automatically added for `.yaml` files, so `structure.yaml` and `file://structure.yaml` work identically. Additionally, if your file is named `.struct.yaml` in the current directory and you want to generate into the current directory, you can just run `struct generate`.
4747
4848
## Discovering Available Structures
4949

docs/usage.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ struct generate <Tab>
3333
# Shows all available structures
3434
```
3535

36+
### Using Defaults
37+
38+
If you have a .struct.yaml in the current directory and want to generate into the current directory, you can simply run:
39+
40+
```sh
41+
struct generate
42+
```
43+
3644
### Simple Example
3745

3846
```sh
@@ -49,6 +57,12 @@ struct generate my-config.yaml ./output
4957
struct generate file://my-config.yaml ./output
5058
```
5159

60+
Tip: If your config file is named `.struct.yaml` in the current directory and you want to generate into the current directory, you can simply run:
61+
62+
```sh
63+
struct generate
64+
```
65+
5266
### Diff Preview Example
5367

5468
```sh

struct_module/commands/generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class GenerateCommand(Command):
1313
def __init__(self, parser):
1414
super().__init__(parser)
1515
parser.description = "Generate the project structure from a YAML configuration file"
16-
structure_arg = parser.add_argument('structure_definition', type=str, help='Path to the YAML configuration file')
16+
structure_arg = parser.add_argument('structure_definition', nargs='?', default='.struct.yaml', type=str, help='Path to the YAML configuration file (default: .struct.yaml)')
1717
structure_arg.completer = structures_completer
18-
parser.add_argument('base_path', type=str, help='Base path where the structure will be created')
18+
parser.add_argument('base_path', nargs='?', default='.', type=str, help='Base path where the structure will be created (default: current directory)')
1919
parser.add_argument('-s', '--structures-path', type=str, help='Path to structure definitions')
2020
parser.add_argument('-n', '--input-store', type=str, help='Path to the input store', default='/tmp/struct/input.json')
2121
parser.add_argument('-d', '--dry-run', action='store_true', help='Perform a dry run without creating any files or directories')

0 commit comments

Comments
 (0)