|
| 1 | +# Command Line Interface — Core Design (v0) |
| 2 | + |
| 3 | +Status: draft |
| 4 | +Scope: the v0 CLI for the `gm` tool. Three commands (`validate`, |
| 5 | +`compile`, `import-owl`) plus global conventions for output, errors, and |
| 6 | +exit codes. Out-of-scope items enumerated in §8. |
| 7 | + |
| 8 | +## 1. Goals |
| 9 | + |
| 10 | +- **Minimal surface.** Three commands cover both user workflows end to |
| 11 | + end. Nothing else ships in v0. |
| 12 | +- **Composable.** Output is just text, stdout is where results go, exit |
| 13 | + codes are honest. `gm compile … | bq query` works; CI parses errors |
| 14 | + with `--json`. |
| 15 | +- **Predictable.** Same inputs → same output. Validation is strict and |
| 16 | + runs implicitly before compilation. |
| 17 | + |
| 18 | +## 2. Workflows |
| 19 | + |
| 20 | +Two starting conditions cover the common cases. |
| 21 | + |
| 22 | +### Condition A: No existing tables (greenfield) |
| 23 | + |
| 24 | +| Step | Action | Command | |
| 25 | +|---|---|---| |
| 26 | +| 1 | Get an ontology: hand-author `finance.ontology.yaml`, or import from OWL | `gm import-owl fibo.ttl --include-namespace <…> -o finance.ontology.yaml` | |
| 27 | +| 2 | Resolve `FILL_IN` placeholders if any | — (text editor) | |
| 28 | +| 3 | Check the ontology is valid | `gm validate finance.ontology.yaml` | |
| 29 | +| 4 | Design and create warehouse tables | — (external) | |
| 30 | +| 5 | Author `finance-bq-prod.binding.yaml` | — (text editor) | |
| 31 | +| 6 | Check the binding | `gm validate finance-bq-prod.binding.yaml` | |
| 32 | +| 7 | Compile to DDL | `gm compile finance-bq-prod.binding.yaml` | |
| 33 | +| 8 | Apply DDL | — (external) | |
| 34 | + |
| 35 | +### Condition B: Existing tables (brownfield) |
| 36 | + |
| 37 | +| Step | Action | Command | |
| 38 | +|---|---|---| |
| 39 | +| 1 | Inspect existing table schemas | — (external) | |
| 40 | +| 2 | Author `finance.ontology.yaml` to describe the tables | — (text editor) | |
| 41 | +| 3 | Check the ontology is valid | `gm validate finance.ontology.yaml` | |
| 42 | +| 4 | Author `finance-bq-prod.binding.yaml` | — (text editor) | |
| 43 | +| 5 | Check the binding | `gm validate finance-bq-prod.binding.yaml` | |
| 44 | +| 6 | Compile to DDL | `gm compile finance-bq-prod.binding.yaml` | |
| 45 | +| 7 | Apply DDL (property graph only; tables already exist) | — (external) | |
| 46 | + |
| 47 | +## 3. Global conventions |
| 48 | + |
| 49 | +### Invocation |
| 50 | + |
| 51 | +Installed binary `gm`. Subcommand style is flat verb-noun hyphenated |
| 52 | +(`gm import-owl`, not `gm import owl`). |
| 53 | + |
| 54 | +### Output destinations |
| 55 | + |
| 56 | +- **stdout** — the primary result: DDL text (`gm compile`), imported |
| 57 | + YAML (`gm import-owl` without `-o`), nothing on success |
| 58 | + (`gm validate`). |
| 59 | +- **stderr** — diagnostics, warnings, human-readable errors. |
| 60 | +- `-o <file>` / `--out <file>` — redirect stdout to a file. Where |
| 61 | + applicable (`gm compile`, `gm import-owl`). |
| 62 | + |
| 63 | +### Exit codes |
| 64 | + |
| 65 | +| Code | Meaning | |
| 66 | +|---|---| |
| 67 | +| 0 | Success. No errors; warnings may have been printed. | |
| 68 | +| 1 | Validation or compilation error (user-fixable). | |
| 69 | +| 2 | Usage error (bad flag, missing file). | |
| 70 | +| 3 | Internal error (unexpected exception). | |
| 71 | + |
| 72 | +### Error format |
| 73 | + |
| 74 | +Default is human-readable, one line per error in the form: |
| 75 | + |
| 76 | +``` |
| 77 | +<file>:<line>:<col>: <rule> — <message> |
| 78 | +``` |
| 79 | + |
| 80 | +Example: |
| 81 | + |
| 82 | +``` |
| 83 | +finance.ontology.yaml:47:5: ontology-r11 — Entity "Account" has no primary key |
| 84 | +``` |
| 85 | + |
| 86 | +`--json` emits a JSON array of structured error objects with fields |
| 87 | +`file`, `line`, `col`, `rule`, `severity` (`error` | `warning`), |
| 88 | +`message`. Warnings do not affect the exit code. |
| 89 | + |
| 90 | +### File conventions |
| 91 | + |
| 92 | +- **Suggested suffixes.** `*.ontology.yaml`, `*.binding.yaml`. The |
| 93 | + loader detects file kind by the top-level key (`ontology:` or |
| 94 | + `binding:`), so any extension is accepted. |
| 95 | +- **OWL source.** File extension selects the parser: `.ttl` (Turtle), |
| 96 | + `.owl` / `.rdf` (RDF/XML). |
| 97 | + |
| 98 | +## 4. `gm validate` |
| 99 | + |
| 100 | +Check that a single YAML file conforms to its spec and cross-references |
| 101 | +resolve. |
| 102 | + |
| 103 | +### Usage |
| 104 | + |
| 105 | +``` |
| 106 | +gm validate <file> |
| 107 | +``` |
| 108 | + |
| 109 | +- Loader detects ontology vs binding from the top-level key. |
| 110 | +- **Ontology** → checked against `ontology.md` §10. |
| 111 | +- **Binding** → checked against `binding.md` §9. The loader also |
| 112 | + attempts to locate the companion ontology (named by `ontology:` in |
| 113 | + the binding, looked up as `<name>.ontology.yaml` in the same |
| 114 | + directory) for cross-validation. If not found, binding validates |
| 115 | + syntactically and the loader emits a warning. |
| 116 | + |
| 117 | +### Flags |
| 118 | + |
| 119 | +| Flag | Purpose | |
| 120 | +|---|---| |
| 121 | +| `--json` | Structured error output (see §3). | |
| 122 | + |
| 123 | +On success, nothing is written to stdout. |
| 124 | + |
| 125 | +## 5. `gm compile` |
| 126 | + |
| 127 | +Emit DDL from a binding. The companion ontology is located by the same |
| 128 | +rule as `gm validate` (§4). |
| 129 | + |
| 130 | +### Usage |
| 131 | + |
| 132 | +``` |
| 133 | +gm compile <binding> [-o <out>] |
| 134 | +``` |
| 135 | + |
| 136 | +- Runs validation implicitly on both files before emission. Any error |
| 137 | + fails the compile; no partial DDL is emitted. |
| 138 | +- Writes DDL to stdout unless `-o` is given. |
| 139 | + |
| 140 | +### Flags |
| 141 | + |
| 142 | +| Flag | Purpose | |
| 143 | +|---|---| |
| 144 | +| `-o <file>`, `--out <file>` | Write DDL to file instead of stdout. | |
| 145 | +| `--json` | Structured errors for the implicit validation step. | |
| 146 | + |
| 147 | +On any validation or compilation error, no DDL is emitted — even partially. |
| 148 | + |
| 149 | +## 6. `gm import-owl` |
| 150 | + |
| 151 | +Read OWL sources and emit a `*.ontology.yaml` (see `owl-import.md`). |
| 152 | + |
| 153 | +### Usage |
| 154 | + |
| 155 | +``` |
| 156 | +gm import-owl <source>... --include-namespace <iri>... [-o <out>] |
| 157 | +``` |
| 158 | + |
| 159 | +- One or more OWL source files (Turtle, RDF/XML). |
| 160 | +- At least one `--include-namespace` required; multiple allowed. |
| 161 | +- Output uses `FILL_IN` for ambiguities and annotations for dropped OWL |
| 162 | + features (see `owl-import.md` §11, §13). `FILL_IN` causes |
| 163 | + `gm validate` to fail until resolved. |
| 164 | + |
| 165 | +### Flags |
| 166 | + |
| 167 | +| Flag | Purpose | |
| 168 | +|---|---| |
| 169 | +| `--include-namespace <iri>` | Required, repeatable. | |
| 170 | +| `-o <file>`, `--out <file>` | Write YAML to file instead of stdout. | |
| 171 | +| `--format ttl\|rdfxml` | Override parser selection from file extension. | |
| 172 | +| `--json` | Structured drop-and-placeholder summary. | |
| 173 | + |
| 174 | +Drop summary is printed to stderr regardless of `--json`. |
| 175 | + |
| 176 | +## 7. Open questions |
| 177 | + |
| 178 | +- **Warnings as errors.** A `--strict` flag that turns warnings into |
| 179 | + exit-1 errors is common in similar tools. Defer until CI users ask. |
| 180 | +- **Log verbosity.** No `--verbose` / `-v` in v0. Validation and |
| 181 | + compile output are already structured enough; add only if |
| 182 | + debugging demands it. |
| 183 | +- **Config file.** A `gm.toml` or similar for per-project defaults |
| 184 | + (namespace filters, target dataset) would simplify repeated |
| 185 | + invocations. Defer until a concrete need surfaces. |
| 186 | + |
| 187 | +## 8. Out of scope |
| 188 | + |
| 189 | +- **`gm init`** — scaffold a minimal project. Users can copy from |
| 190 | + `docs/distillation/examples/` once that exists. |
| 191 | +- **`gm inspect-schema`** — reverse-engineer a skeleton ontology from |
| 192 | + an existing warehouse dataset. Useful for Workflow B but a |
| 193 | + significant amount of backend-specific code. |
| 194 | +- **`gm deploy`** — apply DDL to a live backend. Explicitly off-limits |
| 195 | + per `compilation.md` §1. |
| 196 | +- **`gm diff`** — compare two compilations. Text diff of DDL output |
| 197 | + covers the need. |
| 198 | +- **Shell completion** — post-v0. |
| 199 | +- **Installation and packaging** — separate concern (PyPI, homebrew, |
| 200 | + etc.). |
0 commit comments