[Issue] Provide the option for a user to create a new directory to contain template code on `azd init/up`
Right now, a developer has to manually to create a new directory, cd into the directory and then run azd init/up. If you don't follow this pattern, you can inadvertently download the template code into the current directory. I have personally done this many times and ended up with all the files/folders scattered across the wrong directory on my local machine 😩.
On azd init/up, we should ask the developer if they'd like to create a new directory when downloading the template code (which is a common CLI pattern). If y/yes is input, we create a new directory and download the code in there (mirroring a git clone behaviour). If n/no is input, we assume that the user has already created their own directory and cd'd into it. The goal here would be to guide the developer more through the init/up process.
Love this idea. We should also have the option of specifying the target directory via an invocation parameter.
+1 !
The technical reason for requiring the folder to be created first is because we were having issues with creating a directory and then changing the cwd to that dir. If we do this, then we need to ensure that either:
- We execute all commands in that new directory
- Find a way to CD to that dir in script
- Ask the user to CD to that dir
We have seen this repeatedly, it's a step that can be easily missed. Even for developers who read the Get Started/Readme.
We already have the option -cwd or -C to set the working directory. So, you can run azd up -C ./build to use the build folder from the current directory.
Yes, the folder must be there in order for this to work.
If the folder is not there, we thow exception.
We can improve the experience of using -cwd to detect if the folder is not there and ask user if they want to create it.
When not using -cwd, we could detect if the current directory is not empty, and ask customer to confirm using that path or offering the option of creating a new folder. This way we would not impact people who are already entering the right folder by always making the confirmation/question. We'd do it only when folder is not empty.
What do you think
My impression is that this should be part of the core flow for project initialization or running up. Especially for new developers, using -cwd is less discoverable and complicates the command (which they might be more prone to malforming).
My preferred user flow would be:
- Developer runs
azd init - Developer is presented with template options
- Developer selects a non-empty template
- Developer sees a prompt to either enter a new directory name (to be created as a subdirectory) or they can hit enter to select the current directory
- Developer has code downloaded into the proper directory
- Developer enters new environment name, selects region, selects subscription.
- If developer created a new subdirectory during this flow, we tell them to cd into the directory at the end to continue
We're running into this today during our AI App template usability, and multiple folks did not create a folder, and then got a rude awakening to see that it copied into their current folder instead (and ran git init in it!)
Hi! I am running into same issue too. I would like to help with this if needed. Maybe I can add option to create the folder during azd init flow, and prompt user to choose folder or use current one. Let me know if I can contribute PR! Thanks!
@pamelafox @codeazon thanks for bumping this again.
We provided a warning that the current directory is not empty. Do people still override this warning and proceed, assuming azd will create a template folder and place code there?
azd init -t todo-python-mongo-aca
Initializing an app to run on Azure (azd init)
WARNING: The current directory is not empty.
Initializing an app in this directory may overwrite existing files.
? Continue initializing an app in '/Users/acme/azd-template'? (y/N)
cc: @weikanglim @kristenwomack
It seems so, unless folks were somehow using an old version? We had two Microsoft employees who did it in Monday's study.
azd init is meant to run on current folder (or whatever path set with -cwd global flag). This is good and bad at the same time XD.
It is good because, after running azd init, you don't need to cd into another folder to run your next command. It makes some use cases like CI/CD easier (less instructions).
But it is not so good when you are not in an empty folder and miss the warning from azd init.
I've been wanting to introduce a new command like azd create-project <name> as a command which would:
- Create a new folder using the
<name> - Call
azd init - Cd to
<name>
It would use the same args as azd init for template and branch and it would use the <name> to generate a suggested environment name.
This would be a way to extend the power of azd init
@weikanglim @wbreza @ellismg @jongio @hemarina ... what you think?
Would we then get to move to "azd create-project" for our READMEs? I think that'd be more dev-friendly.
Would we then get to move to "azd create-project" for our READMEs? I think that'd be more dev-friendly.
It would just bring more options for template-owners. If you are currently telling folks in read me to start by creating an empty folder, then cd to the folder and then run azd init, you could migrate to azd create-project.
Intention is basically to cover more scenarios. For some cases, azd init might still be ideal as it is curretly
It seems so, unless folks were somehow using an old version? We had two Microsoft employees who did it in Monday's study.
I'm curious if the warning was presented but skipped (even though you still need to y/n). Do you know?
I've asked them to chime in.
@vhvb1989 - Let's explore other options that include modifying or enhancing azd init versus introducing a new command. I'd prefer something like azd init -t template -f folder or azd init -t template [positional folder argument] (like docker build)
@jongio - Looks like we're on the same page.
I'd propose we support a similar model to the git clone command. Devs are very familiar with the way this command works and in my opinion we shouldn't recreate the wheel.
Init from template without positional path param
azd init -t Azure-Samples/todo-nodejs-mongo-aca
Result: Gets cloned into new todo-nodejs-mongo-aca folder of current path
[!NOTE] This one might be considered a breaking change
Init from template with positional path param
azd init -t Azure-Samples/todo-nodejs-mongo-aca my-project
Result: Gets cloned into my-project folder of current path
Init without template and with positional param
azd init my-project
Result: Initializes new project in the new my-project folder of current path
Init without template or positional param
azd init
Result: Initializes project in current working directory