guard 1.4.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -677
  3. data/LICENSE +4 -2
  4. data/README.md +91 -753
  5. data/bin/_guard-core +11 -0
  6. data/bin/guard +108 -3
  7. data/lib/guard/aruba_adapter.rb +59 -0
  8. data/lib/guard/cli/environments/bundler.rb +22 -0
  9. data/lib/guard/cli/environments/evaluate_only.rb +35 -0
  10. data/lib/guard/cli/environments/valid.rb +69 -0
  11. data/lib/guard/cli.rb +129 -128
  12. data/lib/guard/commander.rb +104 -0
  13. data/lib/guard/commands/all.rb +37 -0
  14. data/lib/guard/commands/change.rb +31 -0
  15. data/lib/guard/commands/notification.rb +26 -0
  16. data/lib/guard/commands/pause.rb +29 -0
  17. data/lib/guard/commands/reload.rb +36 -0
  18. data/lib/guard/commands/scope.rb +38 -0
  19. data/lib/guard/commands/show.rb +24 -0
  20. data/lib/guard/config.rb +18 -0
  21. data/lib/guard/deprecated/dsl.rb +45 -0
  22. data/lib/guard/deprecated/evaluator.rb +39 -0
  23. data/lib/guard/deprecated/guard.rb +328 -0
  24. data/lib/guard/deprecated/guardfile.rb +84 -0
  25. data/lib/guard/deprecated/watcher.rb +27 -0
  26. data/lib/guard/dsl.rb +332 -363
  27. data/lib/guard/dsl_describer.rb +132 -122
  28. data/lib/guard/dsl_reader.rb +51 -0
  29. data/lib/guard/group.rb +34 -14
  30. data/lib/guard/guardfile/evaluator.rb +232 -0
  31. data/lib/guard/guardfile/generator.rb +128 -0
  32. data/lib/guard/guardfile.rb +24 -60
  33. data/lib/guard/interactor.rb +31 -255
  34. data/lib/guard/internals/debugging.rb +68 -0
  35. data/lib/guard/internals/groups.rb +40 -0
  36. data/lib/guard/internals/helpers.rb +13 -0
  37. data/lib/guard/internals/plugins.rb +53 -0
  38. data/lib/guard/internals/queue.rb +51 -0
  39. data/lib/guard/internals/scope.rb +121 -0
  40. data/lib/guard/internals/session.rb +180 -0
  41. data/lib/guard/internals/state.rb +25 -0
  42. data/lib/guard/internals/tracing.rb +33 -0
  43. data/lib/guard/internals/traps.rb +10 -0
  44. data/lib/guard/jobs/base.rb +21 -0
  45. data/lib/guard/jobs/pry_wrapper.rb +336 -0
  46. data/lib/guard/jobs/sleep.rb +26 -0
  47. data/lib/guard/notifier.rb +46 -212
  48. data/lib/guard/options.rb +22 -0
  49. data/lib/guard/plugin.rb +303 -0
  50. data/lib/guard/plugin_util.rb +191 -0
  51. data/lib/guard/rake_task.rb +42 -0
  52. data/lib/guard/runner.rb +80 -140
  53. data/lib/guard/templates/Guardfile +14 -0
  54. data/lib/guard/terminal.rb +13 -0
  55. data/lib/guard/ui/colors.rb +56 -0
  56. data/lib/guard/ui/config.rb +70 -0
  57. data/lib/guard/ui/logger.rb +30 -0
  58. data/lib/guard/ui.rb +163 -128
  59. data/lib/guard/version.rb +1 -2
  60. data/lib/guard/watcher/pattern/deprecated_regexp.rb +45 -0
  61. data/lib/guard/watcher/pattern/match_result.rb +18 -0
  62. data/lib/guard/watcher/pattern/matcher.rb +33 -0
  63. data/lib/guard/watcher/pattern/pathname_path.rb +15 -0
  64. data/lib/guard/watcher/pattern/simple_path.rb +23 -0
  65. data/lib/guard/watcher/pattern.rb +24 -0
  66. data/lib/guard/watcher.rb +52 -95
  67. data/lib/guard.rb +108 -376
  68. data/lib/tasks/releaser.rb +116 -0
  69. data/man/guard.1 +12 -9
  70. data/man/guard.1.html +18 -12
  71. metadata +148 -77
  72. data/images/guard.png +0 -0
  73. data/lib/guard/guard.rb +0 -156
  74. data/lib/guard/hook.rb +0 -120
  75. data/lib/guard/interactors/coolline.rb +0 -64
  76. data/lib/guard/interactors/helpers/completion.rb +0 -32
  77. data/lib/guard/interactors/helpers/terminal.rb +0 -46
  78. data/lib/guard/interactors/readline.rb +0 -94
  79. data/lib/guard/interactors/simple.rb +0 -19
  80. data/lib/guard/notifiers/emacs.rb +0 -69
  81. data/lib/guard/notifiers/gntp.rb +0 -118
  82. data/lib/guard/notifiers/growl.rb +0 -99
  83. data/lib/guard/notifiers/growl_notify.rb +0 -92
  84. data/lib/guard/notifiers/libnotify.rb +0 -96
  85. data/lib/guard/notifiers/notifysend.rb +0 -84
  86. data/lib/guard/notifiers/rb_notifu.rb +0 -102
  87. data/lib/guard/notifiers/terminal_notifier.rb +0 -66
  88. data/lib/guard/notifiers/tmux.rb +0 -69
  89. data/lib/guard/version.rbc +0 -130
data/bin/_guard-core ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "guard"
4
+
5
+ begin
6
+ require "guard/aruba_adapter"
7
+ rescue LoadError => e
8
+ abort "#{e.inspect} - perhaps you need to run using `bundle exec`?"
9
+ end
10
+
11
+ Guard::ArubaAdapter.new(ARGV.dup).execute!
data/bin/guard CHANGED
@@ -1,6 +1,111 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'guard'
4
- require 'guard/cli'
3
+ require "pathname"
5
4
 
6
- Guard::CLI.start
5
+ class GuardReloader
6
+ class Config
7
+ def using_rubygems?
8
+ ENV["RUBYGEMS_GEMDEPS"]
9
+ end
10
+
11
+ def setup_rubygems_for_deps
12
+ require "rubygems"
13
+ end
14
+
15
+ def current_bundler_gemfile
16
+ ENV["BUNDLE_GEMFILE"]
17
+ end
18
+
19
+ def using_bundler?
20
+ ENV["BUNDLE_GEMFILE"]
21
+ end
22
+
23
+ def setup_bundler_env(gemfile)
24
+ ENV["BUNDLE_GEMFILE"] = gemfile
25
+ end
26
+
27
+ def setup_bundler
28
+ require "rubygems"
29
+ require "bundler/setup"
30
+ end
31
+
32
+ def program_path
33
+ Pathname(__FILE__)
34
+ end
35
+
36
+ def program_arguments
37
+ ARGV
38
+ end
39
+
40
+ def windows?
41
+ Gem.win_platform?
42
+ end
43
+
44
+ def exit_with(code)
45
+ exit(code)
46
+ end
47
+
48
+ def spawn_with(*args)
49
+ spawn(*args)
50
+ end
51
+
52
+ def wait_ignoring_interrupts(pid)
53
+ Process.wait2(pid)[1].exitstatus
54
+ rescue Interrupt
55
+ retry
56
+ rescue Errno::ECHILD
57
+ 1
58
+ end
59
+
60
+ def exist?(path)
61
+ path.exist?
62
+ end
63
+
64
+ def guard_core_path
65
+ Gem.bin_path("guard", "_guard-core")
66
+ end
67
+ end
68
+
69
+ attr_reader :config
70
+ def initialize(config)
71
+ @config = config
72
+ end
73
+
74
+ def setup
75
+ return config.setup_bundler if config.using_bundler?
76
+ return config.setup_rubygems_for_deps if config.using_rubygems?
77
+
78
+ # No dependency management detected - check if binstubbed by bundler
79
+ relative_to_binstub = config.program_path + "../../Gemfile"
80
+ if config.exist?(relative_to_binstub)
81
+ config.setup_bundler_env(relative_to_binstub.to_s)
82
+ config.setup_bundler
83
+ return
84
+ end
85
+
86
+ unless config.exist?(Pathname("Gemfile"))
87
+ # Running guard with bare ruby here - it's up to the user
88
+ # to setup/install missing deps
89
+ return
90
+ end
91
+
92
+ STDERR.puts "Warning: you have a Gemfile, but you're not using"\
93
+ " bundler or RUBYGEMS_GEMDEPS"
94
+ end
95
+
96
+ def auto_restart
97
+ args = [Gem.ruby, config.guard_core_path] + config.program_arguments
98
+
99
+ loop do
100
+ exitcode = config.wait_ignoring_interrupts(config.spawn_with(*args))
101
+ config.exit_with(exitcode) if exitcode != 2
102
+ end
103
+ end
104
+ end
105
+
106
+ unless ENV["GUARD_SPECS_RUNNING"]
107
+ config = GuardReloader::Config.new
108
+ reloader = GuardReloader.new(config)
109
+ reloader.setup
110
+ reloader.auto_restart
111
+ end
@@ -0,0 +1,59 @@
1
+ require "guard/cli"
2
+
3
+ module Guard
4
+ class ArubaAdapter
5
+ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR,
6
+ kernel = Kernel)
7
+ @argv = argv
8
+ @stdin = stdin
9
+ @stdout = stdout
10
+ @stderr = stderr
11
+ @kernel = kernel
12
+
13
+ if ENV["INSIDE_ARUBA_TEST"] == "1"
14
+ UI.options = UI.options.merge(flush_seconds: 0)
15
+ end
16
+ end
17
+
18
+ def execute!
19
+ exit_code = execute
20
+ # Proxy our exit code back to the injected kernel.
21
+ @kernel.exit(exit_code)
22
+ end
23
+
24
+ def execute
25
+ # Thor accesses these streams directly rather than letting
26
+ # them be injected, so we replace them...
27
+ $stderr = @stderr
28
+ $stdin = @stdin
29
+ $stdout = @stdout
30
+
31
+ # Run our normal Thor app the way we know and love.
32
+ CLI.start(@argv)
33
+
34
+ # Thor::Base#start does not have a return value, assume
35
+ # success if no exception is raised.
36
+ 0
37
+ rescue StandardError => e
38
+ # The ruby interpreter would pipe this to STDERR and exit 1 in the case
39
+ # of an unhandled exception
40
+ b = e.backtrace
41
+ @stderr.puts "#{b.shift}: #{e.message} (#{e.class})"
42
+ @stderr.puts b.map { |s| "\tfrom #{s}" }.join("\n")
43
+ 1
44
+ rescue SystemExit => e
45
+ e.status
46
+ ensure
47
+ # flush the logger so the output doesn't appear in next CLI invocation
48
+ Guard.listener.stop if Guard.listener
49
+ UI.logger.flush
50
+ UI.logger.close
51
+ UI.reset_logger
52
+
53
+ # ...then we put them back.
54
+ $stderr = STDERR
55
+ $stdin = STDIN
56
+ $stdout = STDOUT
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,22 @@
1
+ require "guard/ui"
2
+
3
+ module Guard
4
+ module Cli
5
+ module Environments
6
+ class Bundler
7
+ def verify
8
+ return unless File.exist?("Gemfile")
9
+ return if ENV["BUNDLE_GEMFILE"] || ENV["RUBYGEMS_GEMDEPS"]
10
+ UI.info <<EOF
11
+
12
+ Guard here! It looks like your project has a Gemfile, yet you are running
13
+ `guard` outside of Bundler. If this is your intent, feel free to ignore this
14
+ message. Otherwise, consider using `bundle exec guard` to ensure your
15
+ dependencies are loaded correctly.
16
+ (You can run `guard` with --no-bundler-warning to get rid of this message.)
17
+ EOF
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ require "guard"
2
+
3
+ module Guard
4
+ module Cli
5
+ module Environments
6
+ class EvaluateOnly
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+
11
+ def evaluate
12
+ # TODO: check bundler setup first?
13
+ #
14
+ # TODO: it should be easier to pass options created with init
15
+ # directly to evaluator
16
+ #
17
+ # TODO: guardfile/DSL should interact only with a given object, and
18
+ # not global Guard object (setting global state only needed before
19
+ # start() is called)
20
+ #
21
+ Guard.init(@options)
22
+ session = Guard.state.session
23
+ Guardfile::Evaluator.new(session.evaluator_options).evaluate
24
+ rescue \
25
+ Dsl::Error,
26
+ Guardfile::Evaluator::NoPluginsError,
27
+ Guardfile::Evaluator::NoGuardfileError,
28
+ Guardfile::Evaluator::NoCustomGuardfile => e
29
+ UI.error(e.message)
30
+ abort
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,69 @@
1
+ require "guard/cli/environments/bundler"
2
+ require "guard/commander"
3
+ require "guard/guardfile/generator"
4
+
5
+ module Guard
6
+ module Cli
7
+ module Environments
8
+ class Valid
9
+ def initialize(options)
10
+ @options = options
11
+ end
12
+
13
+ def start_guard
14
+ # TODO: just to make sure tests are ok
15
+ Bundler.new.verify unless @options[:no_bundler_warning]
16
+ Guard.start(@options)
17
+ rescue Dsl::Error,
18
+ Guardfile::Evaluator::NoPluginsError,
19
+ Guardfile::Evaluator::NoGuardfileError,
20
+ Guardfile::Evaluator::NoCustomGuardfile => e
21
+ # catch to throw message instead of call stack
22
+ UI.error(e.message)
23
+ abort
24
+ end
25
+
26
+ def initialize_guardfile(plugin_names = [])
27
+ bare = @options[:bare]
28
+
29
+ Guard.init(@options)
30
+ session = Guard.state.session
31
+
32
+ generator = Guardfile::Generator.new
33
+ begin
34
+ Guardfile::Evaluator.new(session.evaluator_options).evaluate
35
+ rescue Guardfile::Evaluator::NoGuardfileError
36
+ generator.create_guardfile
37
+ rescue Guard::Guardfile::Evaluator::NoPluginsError
38
+ # Do nothing - just the error
39
+ end
40
+
41
+ return 0 if bare # 0 - exit code
42
+
43
+ # Evaluate because it might have existed and creating was skipped
44
+ begin
45
+ Guardfile::Evaluator.new(session.evaluator_options).evaluate
46
+ rescue Guard::Guardfile::Evaluator::NoPluginsError
47
+ end
48
+
49
+ begin
50
+ if plugin_names.empty?
51
+ generator.initialize_all_templates
52
+ else
53
+ plugin_names.each do |plugin_name|
54
+ generator.initialize_template(plugin_name)
55
+ end
56
+ end
57
+ rescue Guardfile::Generator::Error => e
58
+ UI.error(e.message)
59
+ return 1
60
+ end
61
+
62
+ # TODO: capture exceptions to show msg and return exit code on
63
+ # failures
64
+ 0 # exit code
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
data/lib/guard/cli.rb CHANGED
@@ -1,125 +1,152 @@
1
- require 'thor'
1
+ require "thor"
2
2
 
3
- module Guard
3
+ require "guard/version"
4
+
5
+ require "guard/dsl_describer"
6
+ require "guard/cli/environments/valid"
7
+ require "guard/cli/environments/evaluate_only"
4
8
 
5
- # Facade for the Guard command line interface managed by [Thor](https://github.com/wycats/thor).
6
- # This is the main interface to Guard that is called by the Guard binary `bin/guard`.
7
- # Do not put any logic in here, create a class and delegate instead.
9
+ module Guard
10
+ # Facade for the Guard command line interface managed by
11
+ # [Thor](https://github.com/wycats/thor).
12
+ #
13
+ # This is the main interface to Guard that is called by the Guard binary
14
+ # `bin/guard`. Do not put any logic in here, create a class and delegate
15
+ # instead.
8
16
  #
9
17
  class CLI < Thor
10
-
11
- require 'guard'
12
- require 'guard/version'
13
- require 'guard/dsl_describer'
14
- require 'guard/guardfile'
15
-
16
18
  default_task :start
17
19
 
18
- desc 'start', 'Starts Guard'
20
+ desc "start", "Starts Guard"
19
21
 
20
22
  method_option :clear,
21
- :type => :boolean,
22
- :default => false,
23
- :aliases => '-c',
24
- :banner => 'Auto clear shell before each change/run_all/reload'
23
+ type: :boolean,
24
+ default: false,
25
+ aliases: "-c",
26
+ banner: "Auto clear shell before each action"
25
27
 
26
28
  method_option :notify,
27
- :type => :boolean,
28
- :default => true,
29
- :aliases => '-n',
30
- :banner => 'Notifications feature (growl/libnotify)'
29
+ type: :boolean,
30
+ default: true,
31
+ aliases: "-n",
32
+ banner: "Notifications feature"
31
33
 
32
34
  method_option :debug,
33
- :type => :boolean,
34
- :default => false,
35
- :aliases => '-d',
36
- :banner => 'Show debug information'
35
+ type: :boolean,
36
+ default: false,
37
+ aliases: "-d",
38
+ banner: "Show debug information"
37
39
 
38
40
  method_option :group,
39
- :type => :array,
40
- :default => [],
41
- :aliases => '-g',
42
- :banner => 'Run only the passed groups'
43
-
41
+ type: :array,
42
+ default: [],
43
+ aliases: "-g",
44
+ banner: "Run only the passed groups"
45
+
46
+ method_option :plugin,
47
+ type: :array,
48
+ default: [],
49
+ aliases: "-P",
50
+ banner: "Run only the passed plugins"
51
+
52
+ # TODO: make it plural
44
53
  method_option :watchdir,
45
- :type => :string,
46
- :aliases => '-w',
47
- :banner => 'Specify the directory to watch'
54
+ type: :array,
55
+ aliases: "-w",
56
+ banner: "Specify the directories to watch"
48
57
 
49
58
  method_option :guardfile,
50
- :type => :string,
51
- :aliases => '-G',
52
- :banner => 'Specify a Guardfile'
53
-
54
- # DEPRECATED
55
- method_option :no_vendor,
56
- :type => :boolean,
57
- :default => false,
58
- :aliases => '-I',
59
- :banner => 'DEPRECATED: Ignore vendored dependencies'
60
-
61
- # DEPRECATED
62
- method_option :watch_all_modifications,
63
- :type => :boolean,
64
- :default => false,
65
- :aliases => '-A',
66
- :banner => 'DEPRECATED: Watch for all file modifications including moves and deletions'
59
+ type: :string,
60
+ aliases: "-G",
61
+ banner: "Specify a Guardfile"
67
62
 
68
63
  method_option :no_interactions,
69
- :type => :boolean,
70
- :default => false,
71
- :aliases => '-i',
72
- :banner => 'Turn off completely any guard terminal interactions'
64
+ type: :boolean,
65
+ default: false,
66
+ aliases: "-i",
67
+ banner: "Turn off completely any Guard terminal interactions"
73
68
 
74
69
  method_option :no_bundler_warning,
75
- :type => :boolean,
76
- :default => false,
77
- :aliases => '-B',
78
- :banner => 'Turn off warning when Bundler is not present'
79
-
80
- method_option :show_deprecations,
81
- :type => :boolean,
82
- :default => false,
83
- :banner => 'Turn on deprecation warnings'
70
+ type: :boolean,
71
+ default: false,
72
+ aliases: "-B",
73
+ banner: "Turn off warning when Bundler is not present"
84
74
 
85
75
  # Listen options
86
76
  method_option :latency,
87
- :type => :numeric,
88
- :aliases => '-l',
89
- :banner => 'Overwrite Listen\'s default latency'
77
+ type: :numeric,
78
+ aliases: "-l",
79
+ banner: 'Overwrite Listen\'s default latency'
90
80
 
91
81
  method_option :force_polling,
92
- :type => :boolean,
93
- :default => false,
94
- :aliases => '-p',
95
- :banner => 'Force usage of the Listen polling listener'
82
+ type: :boolean,
83
+ default: false,
84
+ aliases: "-p",
85
+ banner: "Force usage of the Listen polling listener"
86
+
87
+ method_option :wait_for_delay,
88
+ type: :numeric,
89
+ aliases: "-y",
90
+ banner: 'Overwrite Listen\'s default wait_for_delay'
91
+
92
+ method_option :listen_on,
93
+ type: :string,
94
+ aliases: "-o",
95
+ default: nil,
96
+ banner: "Specify a network address to Listen on for "\
97
+ "file change events (e.g. for use in VMs)"
98
+
99
+ def self.help(shell, subcommand = false)
100
+ super
101
+ command_help(shell, default_task)
102
+ end
96
103
 
97
- # Start Guard by initializing the defined Guard plugins and watch the file system.
98
- # This is the default task, so calling `guard` is the same as calling `guard start`.
104
+ # Start Guard by initializing the defined Guard plugins and watch the file
105
+ # system.
106
+ #
107
+ # This is the default task, so calling `guard` is the same as calling
108
+ # `guard start`.
99
109
  #
100
110
  # @see Guard.start
101
111
  #
102
112
  def start
103
- verify_bundler_presence unless options[:no_bundler_warning]
104
- ::Guard.start(options)
105
- rescue Interrupt
106
- ::Guard.stop
107
- abort
113
+ if defined?(JRUBY_VERSION)
114
+ unless options[:no_interactions]
115
+ abort "\nSorry, JRuby and interactive mode are incompatible.\n"\
116
+ "As a workaround, use the '-i' option instead.\n\n"\
117
+ "More info: \n"\
118
+ " * https://github.com/guard/guard/issues/754\n"\
119
+ " * https://github.com/jruby/jruby/issues/2383\n\n"
120
+ end
121
+ end
122
+ exit(Cli::Environments::Valid.new(options).start_guard)
108
123
  end
109
124
 
110
- desc 'list', 'Lists guards that can be used with init'
125
+ desc "list", "Lists Guard plugins that can be used with init"
111
126
 
112
- # List the Guard plugins that are available for use in your system and marks
113
- # those that are currently used in your `Guardfile`.
127
+ # List the Guard plugins that are available for use in your system and
128
+ # marks those that are currently used in your `Guardfile`.
114
129
  #
115
130
  # @see Guard::DslDescriber.list
116
131
  #
117
132
  def list
118
- verify_bundler_presence
119
- ::Guard::DslDescriber.list(options)
133
+ Cli::Environments::EvaluateOnly.new(options).evaluate
134
+ DslDescriber.new.list
135
+ end
136
+
137
+ desc "notifiers", "Lists notifiers and its options"
138
+
139
+ # List the Notifiers for use in your system.
140
+ #
141
+ # @see Guard::DslDescriber.notifiers
142
+ #
143
+ def notifiers
144
+ Cli::Environments::EvaluateOnly.new(options).evaluate
145
+ # TODO: pass the data directly to the notifiers?
146
+ DslDescriber.new.notifiers
120
147
  end
121
148
 
122
- desc 'version', 'Show the Guard version'
149
+ desc "version", "Show the Guard version"
123
150
  map %w(-v --version) => :version
124
151
 
125
152
  # Shows the current version of Guard.
@@ -127,44 +154,37 @@ module Guard
127
154
  # @see Guard::VERSION
128
155
  #
129
156
  def version
130
- verify_bundler_presence
131
- ::Guard::UI.info "Guard version #{ ::Guard::VERSION }"
157
+ $stdout.puts "Guard version #{ VERSION }"
132
158
  end
133
159
 
134
- 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'
160
+ desc "init [GUARDS]", "Generates a Guardfile at the current directory"\
161
+ " (if it is not already there) and adds all installed Guard plugins"\
162
+ " or the given GUARDS into it"
135
163
 
136
164
  method_option :bare,
137
- :type => :boolean,
138
- :default => false,
139
- :aliases => '-b',
140
- :banner => 'Generate a bare Guardfile without adding any installed guard into it'
165
+ type: :boolean,
166
+ default: false,
167
+ aliases: "-b",
168
+ banner: "Generate a bare Guardfile without adding any"\
169
+ " installed plugin into it"
141
170
 
142
171
  # Initializes the templates of all installed Guard plugins and adds them
143
172
  # to the `Guardfile` when no Guard name is passed. When passing
144
173
  # Guard plugin names it does the same but only for those Guard plugins.
145
174
  #
146
- # @see Guard::Guard.initialize_template
147
- # @see Guard::Guard.initialize_all_templates
175
+ # @see Guard::Guardfile.initialize_template
176
+ # @see Guard::Guardfile.initialize_all_templates
148
177
  #
149
- # @param [Array<String>] guard_names the name of the Guard plugins to initialize
178
+ # @param [Array<String>] plugin_names the name of the Guard plugins to
179
+ # initialize
150
180
  #
151
- def init(*guard_names)
152
- verify_bundler_presence
153
-
154
- ::Guard::Guardfile.create_guardfile(:abort_on_existence => options[:bare])
155
-
156
- return if options[:bare]
157
-
158
- if guard_names.empty?
159
- ::Guard::Guardfile::initialize_all_templates
160
- else
161
- guard_names.each do |guard_name|
162
- ::Guard::Guardfile.initialize_template(guard_name)
163
- end
164
- end
181
+ def init(*plugin_names)
182
+ env = Cli::Environments::Valid.new(options)
183
+ exitcode = env.initialize_guardfile(plugin_names)
184
+ exit(exitcode)
165
185
  end
166
186
 
167
- desc 'show', 'Show all defined Guard plugins and their options'
187
+ desc "show", "Show all defined Guard plugins and their options"
168
188
  map %w(-T) => :show
169
189
 
170
190
  # Shows all Guard plugins and their options that are defined in
@@ -173,27 +193,8 @@ module Guard
173
193
  # @see Guard::DslDescriber.show
174
194
  #
175
195
  def show
176
- verify_bundler_presence
177
- ::Guard::DslDescriber.show(options)
196
+ Cli::Environments::EvaluateOnly.new(options).evaluate
197
+ DslDescriber.new.show
178
198
  end
179
-
180
- private
181
-
182
- # Verifies if Guard is run with `bundle exec` and
183
- # shows a hint to do so if not.
184
- #
185
- def verify_bundler_presence
186
- if File.exists?('Gemfile') && !ENV['BUNDLE_GEMFILE']
187
- ::Guard::UI.info <<EOF
188
-
189
- Guard here! It looks like your project has a Gemfile, yet you are running
190
- `guard` outside of Bundler. If this is your intent, feel free to ignore this
191
- message. Otherwise, consider using `bundle exec guard` to ensure your
192
- dependencies are loaded correctly.
193
- (You can run `guard` with --no-bundler-warning to get rid of this message.)
194
- EOF
195
- end
196
- end
197
-
198
199
  end
199
200
  end