consolidation / annotated-command

Create Symfony Console commands from annotated command class methods.
Other
221 stars 37 forks source link

Standard naming conventions and search locations for command files #12

Closed greg-1-anderson closed 8 years ago

greg-1-anderson commented 8 years ago

Currently, the CommandFileDiscovery class searches for command files named *Commands.php in directories named CliTools (or src/CliTools).

In Drush, I tried an alternative search pattern, and currently look for command files named "*CommandFile.php" in directories named CommandFiles (or src/CommandFiles).

Ideally, we should decide on a single standard default that both Drush and DrupalConsole can use, so that command files are found consistently. At the moment, I am leaning towards the second option, and calling these literally CommandFiles, as Drush is currently doing. Other conventions are possible, of course; anyone with opinions on the subject should weigh in.

weitzman commented 8 years ago

No strong opinion here. I think the File suffix is a bit redundant (and Tools as well).

greg-1-anderson commented 8 years ago

Symfony Console searches for *Command.php in Command, so we shouldn't use that.

Other options:

*Commands.php in Commands *Cli.php in Cli

greg-1-anderson commented 8 years ago

Another thing that would be sensible would be to search for *Commands.php in Command -- same directory as Symfony Console's standard, but a (slightly) different filename. Symfony Console command files implement one command -- annotation command files can provide multiple commands.

itsdarrylnorris commented 8 years ago

My two cents....

I personally like the structure that Symfony Console provide *Command.php in src/Command. I think is going to be confusing for anyone that have to contribute before to a Symfony Console project and is now trying to contribute to either Drush or Drupal Console.

Since this mainly for support for annotation commands what about *Annotation.php in src/Command/Annotation/ or src/Annotation. This will allow users to either write commands in the Symfony Console way or Annotation way.

greg-1-anderson commented 8 years ago

Yes, I agree that it should be possible to write either a Symfony Console command or a new annotation command. The proposed PR in DrupalConsole, https://github.com/hechoendrupal/DrupalConsole/pull/2081, supports this.

Annotations can be used for many things other than defining commands, though, so I think that *Annotation.php is a bit too generic, and src/Annotation is a little too hidden. I like sharing src/Command, since that makes the new commands discoverable. src/Command/Annotation is at least in the right location, but I tend to think that someone who was familiar with Symfony would expect to see annotations that affect Symfony commands in that location -- not more commands. *Commands.php has the advantage of being short and visible.

src/Command/*AnnotationCommand.php would also meet all of the criteria, but is a bit long.

greg-1-anderson commented 8 years ago

src/Command/*AnnotatedCommand.php is another viable alternative.

greg-1-anderson commented 8 years ago

I prefer the shorter variation myself, but am not super strongly attached with it, and could go with ^^ if that's what most folks want to see.

fago commented 8 years ago

I think the command classes miss a neat name, "command class instance" is a bit long and clumsy. What about just going with CommandHandler? Then we could use a CommandHandler namespace and have a clear differentation to CommandHandlers that provide multiple commands and Command classes ?

greg-1-anderson commented 8 years ago

Ended up leaving the defaults as they were. Each individual project may set the search locations they prefer, though.