Skip to content

apps init: allow scaffolding into the current directory#5247

Merged
andrewnester merged 2 commits into
mainfrom
jorge.calvar/apps_init_same_dir
May 13, 2026
Merged

apps init: allow scaffolding into the current directory#5247
andrewnester merged 2 commits into
mainfrom
jorge.calvar/apps_init_same_dir

Conversation

@calvarjorge
Copy link
Copy Markdown
Contributor

What changes

Non-interactive: --name .

  • databricks apps init --name . scaffolds directly into the current
    working directory.
  • The app name is derived from the cwd basename and validated against the
    existing project-name rules ([a-z][a-z0-9-]*, ≤ 26 chars). An invalid
    basename produces an actionable error pointing at renaming the directory.
  • The cwd must be empty other than .git/ and .gitignore, so the common
    mkdir foo && cd foo && git init flow still works while avoiding any
    risk of overwriting existing user files.
  • --name . and --output-dir are mutually exclusive (one already names
    the destination).
  • The cd <name> line in the success / next-steps output is omitted when
    scaffolding in place.

Interactive

When the cwd is eligible for in-place use (empty modulo .git/.gitignore,
valid basename), the user is asked up front:

Where should we create the app?
▸ Create a new subdirectory       (default)
  Use the current directory ("foo")

The default focused option is "Create a new subdirectory", so anyone who
hits Enter through prompts gets today's behaviour. The in-place option is
opt-in but discoverable. If the cwd isn't eligible, the existing name
prompt runs unchanged.

Test plan

Build the CLI from this branch:

```
go build -o ./cli
```

Then try the new flow:

```

In-place scaffold (non-interactive)

mkdir /tmp/my-app && cd /tmp/my-app
git init
~/path/to/cli apps init --name .
ls -A # files land at the top level, no nested my-app/

In-place scaffold (interactive)

mkdir /tmp/foo && cd /tmp/foo
~/path/to/cli apps init # first prompt is the new selector
```

Unit tests: `go test ./cmd/apps/... ./libs/apps/prompt/...`.

`databricks apps init --name .` now scaffolds the AppKit template into
the current working directory instead of always creating a subdirectory.
The app name is derived from the cwd basename and validated against the
existing project-name rules. The directory must be empty modulo `.git/`
and `.gitignore`, which keeps the `mkdir foo && cd foo && git init`
flow working without risking overwrites.

In interactive mode, when the cwd is eligible for in-place use, the
user is asked up front whether to create a new subdirectory (default)
or use the current directory; the existing name prompt is otherwise
unchanged.

Co-authored-by: Isaac
… flow

Three fixes for the in-place scaffolding path:

- Drop .gitignore from the allow-list. The template's _gitignore rename
  writes .gitignore via os.WriteFile with no exists-check, so a pre-existing
  .gitignore was silently overwritten.
- Reject symlinks named like any allow-listed entry in CheckInPlaceDirectory.
  Without this, a symlink named .git (or any future allow-listed dotfile)
  let os.WriteFile follow the link and overwrite an arbitrary writable file.
- Skip the interactive in-place offer when --output-dir is set, and reject
  "." typed at the prompt in that case. Both interactive paths previously
  silently dropped --output-dir; now they return the same sentinel error
  the explicit --name . flag uses.

Also factors out validateProjectNameForPrompt so the sentinel + outputDir
rules are unit-testable without a TTY.

Co-authored-by: Isaac
@andrewnester andrewnester merged commit c659c3c into main May 13, 2026
31 of 32 checks passed
@andrewnester andrewnester deleted the jorge.calvar/apps_init_same_dir branch May 13, 2026 11:47
denik pushed a commit that referenced this pull request May 20, 2026
## What changes

### Non-interactive: `--name .`

- `databricks apps init --name .` scaffolds directly into the current
  working directory.
- The app name is derived from the cwd basename and validated against
the
existing project-name rules (`[a-z][a-z0-9-]*`, ≤ 26 chars). An invalid
basename produces an actionable error pointing at renaming the
directory.
- The cwd must be empty other than `.git/` and `.gitignore`, so the
common
  `mkdir foo && cd foo && git init` flow still works while avoiding any
  risk of overwriting existing user files.
- `--name .` and `--output-dir` are mutually exclusive (one already
names
  the destination).
- The `cd <name>` line in the success / next-steps output is omitted
when
  scaffolding in place.

### Interactive

When the cwd is eligible for in-place use (empty modulo
`.git`/`.gitignore`,
valid basename), the user is asked up front:

```
Where should we create the app?
▸ Create a new subdirectory       (default)
  Use the current directory ("foo")
```

The default focused option is "Create a new subdirectory", so anyone who
hits Enter through prompts gets today's behaviour. The in-place option
is
opt-in but discoverable. If the cwd isn't eligible, the existing name
prompt runs unchanged.

## Test plan

Build the CLI from this branch:

\`\`\`
go build -o ./cli
\`\`\`

Then try the new flow:

\`\`\`
# In-place scaffold (non-interactive)
mkdir /tmp/my-app && cd /tmp/my-app
git init
~/path/to/cli apps init --name .
ls -A   # files land at the top level, no nested my-app/

# In-place scaffold (interactive)
mkdir /tmp/foo && cd /tmp/foo
~/path/to/cli apps init   # first prompt is the new selector
\`\`\`

Unit tests: \`go test ./cmd/apps/... ./libs/apps/prompt/...\`.
TanishqDatabricks pushed a commit to TanishqDatabricks/cli that referenced this pull request May 22, 2026
)

## What changes

### Non-interactive: `--name .`

- `databricks apps init --name .` scaffolds directly into the current
  working directory.
- The app name is derived from the cwd basename and validated against
the
existing project-name rules (`[a-z][a-z0-9-]*`, ≤ 26 chars). An invalid
basename produces an actionable error pointing at renaming the
directory.
- The cwd must be empty other than `.git/` and `.gitignore`, so the
common
  `mkdir foo && cd foo && git init` flow still works while avoiding any
  risk of overwriting existing user files.
- `--name .` and `--output-dir` are mutually exclusive (one already
names
  the destination).
- The `cd <name>` line in the success / next-steps output is omitted
when
  scaffolding in place.

### Interactive

When the cwd is eligible for in-place use (empty modulo
`.git`/`.gitignore`,
valid basename), the user is asked up front:

```
Where should we create the app?
▸ Create a new subdirectory       (default)
  Use the current directory ("foo")
```

The default focused option is "Create a new subdirectory", so anyone who
hits Enter through prompts gets today's behaviour. The in-place option
is
opt-in but discoverable. If the cwd isn't eligible, the existing name
prompt runs unchanged.

## Test plan

Build the CLI from this branch:

\`\`\`
go build -o ./cli
\`\`\`

Then try the new flow:

\`\`\`
# In-place scaffold (non-interactive)
mkdir /tmp/my-app && cd /tmp/my-app
git init
~/path/to/cli apps init --name .
ls -A   # files land at the top level, no nested my-app/

# In-place scaffold (interactive)
mkdir /tmp/foo && cd /tmp/foo
~/path/to/cli apps init   # first prompt is the new selector
\`\`\`

Unit tests: \`go test ./cmd/apps/... ./libs/apps/prompt/...\`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants