Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Previously, azd failed immediately when -C/--cwd pointed to a non-existent directory. This required users to manually create directories before running commands like azd init -t template -C ./new-folder.

Changes

Modified PersistentPreRunE in cmd/root.go:

  • Check directory existence before os.Chdir
  • Prompt user to create if missing (default: Yes)
  • Auto-create with --no-prompt flag
  • Support nested paths via os.MkdirAll

Added test coverage:

  • Single-level directory creation
  • Nested directory creation (parent/child/project)

Usage

# Interactive mode - prompts with default Yes
azd init -t azure-samples/todo-nodejs-mongo -C ./new-folder

# Non-interactive - auto-creates
azd init -t azure-samples/todo-nodejs-mongo -C ./new-folder --no-prompt

# Nested paths supported
azd init -t template -C ./parent/child/project --no-prompt

Fixes #3680

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /home/REDACTED/work/azure-dev/azure-dev/cli/azd/azd-test init -t azure-samples/todo-nodejs-mongo -C ./new-folder (dns block)
    • Triggering command: /home/REDACTED/work/azure-dev/azure-dev/cli/azd/azd-test init -t azure-samples/todo-nodejs-mongo -C ./new-folder --no-prompt (dns block)
    • Triggering command: /home/REDACTED/work/azure-dev/azure-dev/cli/azd/azd-test telemetry upload (dns block)
  • westus-0.in.applicationinsights.azure.com
    • Triggering command: /home/REDACTED/work/azure-dev/azure-dev/cli/azd/azd-test telemetry upload (dns block)
    • Triggering command: /home/REDACTED/work/azure-dev/azure-dev/cli/azd/azd telemetry upload (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

See issue: #3680

I think we could re-use the -C, --cwd path here.

Right now, if we try to use it for some path that does not exist, azd fails, like

$ azd init -t azure/azure-dev -C ./new-folder
Error: failed to change directory to ./new-folder: chdir ./new-folder: no such file or directory

Azd should ask user if they want to create the folder when it does not exists - using Yes as the default value for the confirmation


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add confirmation for creating directory in azd init Prompt to create directory when using -C/--cwd with non-existent path Nov 20, 2025
Copilot AI requested a review from vhvb1989 November 20, 2025 05:55
Copilot finished work on behalf of vhvb1989 November 20, 2025 05:55
@vhvb1989 vhvb1989 marked this pull request as ready for review November 20, 2025 21:55
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.

[Feature Request] AZD init with folder parameter

2 participants