Class: Belt::CLI::TasksCommand
- Inherits:
-
Object
- Object
- Belt::CLI::TasksCommand
- Defined in:
- lib/belt/cli/tasks_command.rb
Class Method Summary collapse
-
.invoke(task_name, args) ⇒ Object
Invoke a specific rake task by name.
-
.rake_task?(name) ⇒ Boolean
Check if a given command name looks like a rake task that exists.
- .run(args) ⇒ Object
Instance Method Summary collapse
-
#initialize(args) ⇒ TasksCommand
constructor
A new instance of TasksCommand.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ TasksCommand
Returns a new instance of TasksCommand.
33 34 35 36 |
# File 'lib/belt/cli/tasks_command.rb', line 33 def initialize(args) @options = {} (args) end |
Class Method Details
.invoke(task_name, args) ⇒ Object
Invoke a specific rake task by name
24 25 26 27 28 29 30 31 |
# File 'lib/belt/cli/tasks_command.rb', line 24 def self.invoke(task_name, args) unless File.exist?('Rakefile') || File.exist?('rakefile') || File.exist?('Rakefile.rb') abort "Error: No Rakefile found. Cannot run task '#{task_name}'." end cmd = ['bundle', 'exec', 'rake', task_name] + args exec(*cmd) end |
.rake_task?(name) ⇒ Boolean
Check if a given command name looks like a rake task that exists
14 15 16 17 18 19 20 21 |
# File 'lib/belt/cli/tasks_command.rb', line 14 def self.rake_task?(name) return false unless name.include?(':') || name.match?(/\A[a-z_]+\z/) return false unless File.exist?('Rakefile') || File.exist?('rakefile') || File.exist?('Rakefile.rb') # Only treat colon-namespaced commands as potential rake tasks to avoid # ambiguity with belt's own commands name.include?(':') end |
.run(args) ⇒ Object
9 10 11 |
# File 'lib/belt/cli/tasks_command.rb', line 9 def self.run(args) new(args).run end |
Instance Method Details
#run ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/belt/cli/tasks_command.rb', line 38 def run abort 'Error: No Rakefile found. Add a Rakefile to your project to discover tasks.' unless rakefile_available? tasks = load_tasks tasks = apply_grep(tasks) if @options[:grep] if tasks.empty? puts 'No rake tasks found.' else output_tasks(tasks) end end |