lando / cli

The cli part of Lando
https://docs.lando.dev/cli
GNU General Public License v3.0
29 stars 34 forks source link

Duplicate project name detection and prevention #150

Open matpratta opened 2 years ago

matpratta commented 2 years ago

Lando v3.6.5 here, but also happens on v3.6.4

Basically, the main issue here is that if you have two projects/directories with different recipes/plugins being used, Lando will not pick up the recipe/plugin specified in the current Landofile and not only will show you invalid commands if you run lando --help, but also will completely ignore any commands valid for the active Landofile.

Reproduction:

  1. Create directories lando-A and lando-B
  2. Initialize Laravel on lando-A
  3. Run lando --help and take note of the options, lando artisan and lando laravel should be present
  4. Initialize WordPress on lando-B
  5. Run lando --help and take note of the options, lando wp should be present
  6. You will note that in one of the cases above it won't behave correctly. Either Laravel options will show up on WordPress or vice-versa

The only thing I found that fixes this situation is going to the project directory and running lando start or lando rebuild. It seems to update some sort of cache and becomes the "current" Lando application.

A bit related, but something I noticed is that it's possible to run Lando commands such as lando laravel before starting or rebuilding the project for the first time. This leads to a bit of confusion because it will start the containers just as one would expect, but not download any CLI binaries, which will lead to an error saying the binary was not found.

Hope the report is somehow helpful, I've been using Lando for about a month now and it's a quite useful tool! Just found those small details to be a bit confusing or unexpected...

matpratta commented 2 years ago

A quick update on this, as @gitressa pointed out in my other Issue, seems like this is caused because I had the same app name for both the WordPress and Laravel app. Maybe the app tried to cache it somehow and kept conflicting, but naming things correctly fixes the issue. Sorry, my bad.

gitressa commented 2 years ago

Thanks for creating this issue @MatheusMK3. It is important to not have identical names for different .lando files, since they will otherwise affect each other. But it is currently up to the user to make sure of this, which is not ideal ...

The easiest and most efficient way of starting all over with fresh Lando instances, should you ever need it again, is this method: https://docs.lando.dev/help/purging-containers.html

@labboy0276: Is it somehow possible to block the creation of a Lando instance, if the name already exists? Perhaps something like this?

$ lando init --recipe drupal9 --name my-lando-app --source cwd --webroot web
Sorry, the name my-lando-app already exists, please pick another name.

... as well as:

$ lando init
? From where should we get your app's codebase? current working directory
? What recipe do you want to use? wordpress
? Where is your webroot relative to the init destination? .
? What do you want to call this app? my-lando-app
Sorry, the name my-lando-app already exists, please pick another name.
labboy0276 commented 2 years ago

@gitressa I will rename this issue and make it a feature request. We are all heads down on Lando 4 stuffs now, so I don't think it will be considered for quite sometime.

gitressa commented 2 years ago

@labboy0276 I am looking forward to Lando 4, and agree that you should totally focus on getting that done first.

matpratta commented 2 years ago

Glad to see this might come as an improvement! Looking forward to it!