cli icon indicating copy to clipboard operation
cli copied to clipboard

Fix duplicate --env options

Open cllns opened this issue 1 year ago • 0 comments

With Hanami 2.2.1, --env shows up twice for generate commands.

Options:
  --env=VALUE, -e VALUE             # App environment (development, test, production)
  --slice=VALUE                     # Slice name
  --env=VALUE, -e VALUE             # App environment (development, test, production)
  --help, -h                        # Print this help

This is due to klass.prepend(Environment) being run twice whenever we subclass App::Command (like we do for App::Generate::Command)

This change fixes that... ~but it breaks our specs for the feature that automatically runs db commands in test env when running them for development, from #247~

~I think it's because the prepending the Environment module several times ensures it's at the top of the ancestors list.~

For hanami db migrate failure:

# self.class.ancestors inside the Migrate command manually formatted for reading
[
  Hanami::CLI::Commands::App::Command::Environment
  Hanami::CLI::Commands::App::DB::Migrate, 
  Hanami::CLI::Commands::App::Command::Environment, 
  Hanami::CLI::Commands::App::DB::Command, 
  Hanami::CLI::Commands::App::Command, 
  Hanami::CLI::Command, 
  Dry::CLI::Command, 
  Object, 
  JSON::Ext::Generator::GeneratorMethods::Object, 
  Kernel, 
  BasicObject
]

You can see Environment is duplicated there, and at the start of the list.

UPDATE I solved this at the point of adding the option rather than including the module and CI passes now, and only one --env option shows up, so the double prepare doesn't appear to cause any problems.

cllns avatar Nov 26 '24 03:11 cllns