databricks-cli/libs/cmdio
shreyas-goenka 41a21af556
Refactor `bundle init` (#2074)
## Summary of changes
This PR introduces three new abstractions: 
1. `Resolver`: Resolves which reader and writer to use for a template.
2. `Writer`: Writes a template project to disk. Prompts the user if
necessary.
3. `Reader`: Reads a template specification from disk, built into the
CLI or from GitHub.

Introducing these abstractions helps decouple reading a template from
writing it. When I tried adding telemetry for the `bundle init` command,
I noticed that the code in `cmd/init.go` was getting convoluted and hard
to test. A future change could have accidentally logged PII when a user
initialised a custom template.

Hedging against that risk is important here because we use a generic
untyped `map<string, string>` representation in the backend to log
telemetry for the `databricks bundle init`. Otherwise, we risk
accidentally breaking our compliance with our centralization
requirements.

### Details

After this PR there are two classes of templates that can be
initialized:
1. A `databricks` template: This could be a builtin template or a
template outside the CLI like mlops-stacks, which is still owned and
managed by Databricks. These templates log their telemetry arguments and
template name.
2. A `custom` template: These are templates created by and managed by
the end user. In these templates we do not log the template name and
args. Instead a generic placeholder string of "custom" is logged in our
telemetry system.

NOTE: The functionality of the `databricks bundle init` command remains
the same after this PR. Only the internal abstractions used are changed.

## Tests
New unit tests. Existing golden and unit tests. Also a fair bit of
manual testing.
2025-01-20 12:09:28 +00:00
..
context.go Add bundle destroy command (#300) 2023-04-06 12:54:58 +02:00
error_event.go Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
event.go Move state to event for whether they support inplace progress logging (#339) 2023-04-18 14:20:35 +02:00
io.go Refactor `bundle init` (#2074) 2025-01-20 12:09:28 +00:00
io_test.go Do not allow input prompts in Git Bash terminal (#1069) 2023-12-18 15:01:59 +00:00
logger.go Enable linter 'unconvert' and fix the issues found (#2136) 2025-01-14 10:56:38 +00:00
logger_test.go Add support for multiline descriptions when using template enums (#916) 2023-10-25 09:37:25 +00:00
message_event.go Log mutator messages using progress logger (#312) 2023-04-18 16:55:06 +02:00
render.go Enable intrange linter and apply autofix (#2069) 2025-01-03 09:25:07 +00:00
render_test.go Enable linter 'mirror' and autofix existing issues (#2070) 2025-01-03 10:13:12 +00:00
testing.go Prompt once for a client profile (#727) 2023-09-11 15:32:24 +00:00