Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain register #2953

Closed
wants to merge 18 commits into from
Closed

Conversation

marcelovani
Copy link
Member

@marcelovani marcelovani commented Nov 16, 2016

ClassRegister

This is a proof of concept.
I would like to be able to call chain commands without having to specify --file or other arguments, because it takes too much time to write them. I would like to just type

drupal chain:someting

Also, since site:new is not currently available, I would like to have it as a chain command

drupal chain:site:new
This would be the content of the chain-site-new.yml

commands:
## Build from template
  - command: exec
    arguments:
      bin: 'composer create-project %{{project|dennisdigital/drupal-project:8.x-dev}}:%{{version|8.x-dev}} %{{directory|/vagrant/repos/new-site}} --stability dev --no-interaction'

Say I want to put this on jenkins, I would have to do

drupal chain --file=/pathtofile/chain-site-new.yml --parameter="profile:profile_name" --parameter="directory:/somedir" --parameter="version:8.1"

With this prototype, I can skip the --file

Another possibility is to have a chain calling another chain.

Chain calling another chain

chain-test-child.yml

commands:
# This chain shows the variables passed either via placeholders or interactive mode
  - command: exec
    arguments:
      bin: 'echo "This is a test: Project:%{{project|foo}} Directory:%{{directory|bar}}"'

Calling this chain:

drupal chain:test:child
The interactive mode will ask you the values for project and directory, with default values 'foo' and 'bar' respectively.

Enter placeholder value for project [foo]:
Enter placeholder value for directory [bar]:

The output will be:
This is a test: Project:foo Directory:bar

Main chain calling a child chain

chain-test-main.yml

commands:
# Example of a chain calling another chain with placeholders
# In interactive mode, it will ask you to provide the project, default value is 'main-project'
  - command: chain:test:child
    options:
      placeholder:
        - 'project:%{{project|main-project}}'
        - 'directory:main-dir'

Calling this chain:

drupal chain:test:main
The interactive mode will ask you the values for project, with default values 'main-project'. Directory has a fixed value in this example.

Enter placeholder value for project [main-project]:

The output will be:
This is a test: Project:main-project Directory:main-dir

How to make ChainRegister find your chains

Copy your yml files to any folder
Place the chain.yml in the console folder (same location where config.yml is)

chain.yml

chain:
  name:
    'test:main':
      file: 'pathto/chain-main.yml'
    'test:child':
      file: 'pathto/chain-child.yml'

ps: The name of your chain will be prepended with 'chain:' automatically.

@marcelovani
Copy link
Member Author

I merged the latest changes from master to my branch. The code isn't working now, because Config.php was deleted and I don't know how to point to chain.yml

@@ -0,0 +1,6 @@
# Chains listed here will be auto loaded by the ChainRegister.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is no longer required on this PR

$this->add($command);
}

$autoWireForcedCommands = $this->getConfig()->get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove from 123 to 127 those lines got relocated to drupal-console-core

@@ -107,6 +108,24 @@ private function registerCommands()
$logger->writeln($this->trans('application.site.errors.settings'));
}

$chainCommands = $this->getConfig()->get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove from 111 to 115 the loading commands will not be reading a config file.
I will write the implementation

@marcelovani
Copy link
Member Author

Moved PR to the sponsoring company github account https://github.com/hechoendrupal/DrupalConsole/pull/2961/files

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.

None yet

2 participants