Skip to content

Commit

Permalink
Merge pull request guard#301 from jredville/multiple_init
Browse files Browse the repository at this point in the history
Multiple init
  • Loading branch information
thibaudgg committed Jul 10, 2012
2 parents a6eff23 + 5998e34 commit 815ca3d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
## Master

- Add support for multiple guards being passed to `guard init`. ([@jredville][])

### 1.2.1 - 2 Juli, 2012

### Bug fix
Expand Down Expand Up @@ -630,3 +632,4 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@wereHamster]: https://github.com/wereHamster
[@yannlugrin]: https://github.com/yannlugrin
[@zonque]: https://github.com/zonque
[@jredville]: https://github.com/jredville
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -225,6 +225,13 @@ in the generated Guardfile:
$ guard init <guard-name>
```

You can also specify the names of multiple plugins to only get those plugin templates
in the generated Guardfile:

```bash
$ guard init <guard1-name> <guard2-name>
```

You can also define your own templates in `~/.guard/templates/` which can be appended in the same way to your existing
`Guardfile`:

Expand Down
14 changes: 8 additions & 6 deletions lib/guard/cli.rb
Expand Up @@ -127,7 +127,7 @@ def version
::Guard::UI.info "Guard version #{ ::Guard::VERSION }"
end

desc 'init [GUARD]', 'Generates a Guardfile at the current directory (if it is not already there) and adds all installed guards or the given GUARD into it'
desc 'init [GUARDS]', 'Generates a Guardfile at the current directory (if it is not already there) and adds all installed guards or the given GUARDS into it'

method_option :bare,
:type => :boolean,
Expand All @@ -137,24 +137,26 @@ def version

# Initializes the templates of all installed Guard pluginss and adds them
# to the `Guardfile` when no Guard name is passed. When passing
# a Guard plugin name it does the same but only for that Guard plugin.
# Guard plugin names it does the same but only for those Guard plugins.
#
# @see Guard::Guard.initialize_template
# @see Guard::Guard.initialize_all_templates
#
# @param [String] guard_name the name of the Guard plugin to initialize
# @param [Array<String>] guard_names the name of the Guard plugins to initialize
#
def init(guard_name = nil)
def init(*guard_names)
verify_bundler_presence

::Guard::Guardfile.create_guardfile(:abort_on_existence => options[:bare])

return if options[:bare]

if guard_name.nil?
if guard_names.empty?
::Guard::Guardfile::initialize_all_templates
else
::Guard::Guardfile.initialize_template(guard_name)
guard_names.each do |guard_name|
::Guard::Guardfile.initialize_template(guard_name)
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions man/guard.1
Expand Up @@ -53,11 +53,11 @@ The following options are available:
.P
\fB\-p\fR, \fB\-\-force\-polling\fR Force usage of the Listen polling listener\.
.
.SS "init [GUARD]"
.SS "init [GUARDS]"
If no Guardfile is present in the current directory, creates an empty Guardfile\.
.
.P
If \fIGUARD\fR is present, add its default Guardfile configuration to the current Guardfile\. Note that \fIGUARD\fR is the Guard plugin name without the \fBguard\-\fR prefix\. For instance to initialize guard\-rspec, run \fBguard init rspec\fR\.
If \fIGUARDS\fR are present, add their default Guardfile configuration to the current Guardfile\. Note that \fIGUARDS\fR is a list of the Guard plugin names without the \fBguard\-\fR prefix\. For instance to initialize guard\-rspec, run \fBguard init rspec\fR\.
.
.SS "list"
Lists Guard plugins that can be used with the \fBinit\fR command\.
Expand Down
6 changes: 3 additions & 3 deletions man/guard.1.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/guard.1.ronn
Expand Up @@ -47,19 +47,19 @@ The following options are available:

`--show-deprecations`
Turn on deprecation warnings.

`-l`, `--latency`
Overwrite Listen's default latency.

`-p`, `--force-polling`
Force usage of the Listen polling listener.

### init [GUARD]
### init [GUARDS]

If no Guardfile is present in the current directory, creates an empty Guardfile.

If <GUARD> is present, add its default Guardfile configuration to the current Guardfile.
Note that <GUARD> is the Guard plugin name without the `guard-` prefix.
If <GUARDS> are present, add their default Guardfile configuration to the current Guardfile.
Note that <GUARDS> is a list of the Guard plugin names without the `guard-` prefix.
For instance to initialize guard-rspec, run `guard init rspec`.

### list
Expand Down
7 changes: 7 additions & 0 deletions spec/guard/cli_spec.rb
Expand Up @@ -184,6 +184,13 @@
subject.init
end

it 'initializes each passed template by delegating to Guardfile.initialize_template' do
Guard::Guardfile.should_receive(:initialize_template).with('rspec')
Guard::Guardfile.should_receive(:initialize_template).with('pow')

subject.init 'rspec','pow'
end

context 'when passed a guard name' do
it 'initializes the template of the passed Guard by delegating to Guardfile.initialize_template' do
Guard::Guardfile.should_receive(:initialize_template).with('rspec')
Expand Down

0 comments on commit 815ca3d

Please sign in to comment.