Class: MaintenanceTasks::CLI
- Inherits:
-
Thor
- Object
- Thor
- MaintenanceTasks::CLI
- Defined in:
- lib/maintenance_tasks/cli.rb
Overview
Defines the command line interface commands exposed by Maintenance Tasks in the executable file.
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Return a failed exit status in case of an error.
Instance Method Summary collapse
-
#list ⇒ Object
Command to list all available Tasks.
-
#perform(name) ⇒ Object
Command to run a Task.
Class Method Details
.exit_on_failure? ⇒ Boolean
Return a failed exit status in case of an error.
12 13 14 |
# File 'lib/maintenance_tasks/cli.rb', line 12 def exit_on_failure? true end |
Instance Method Details
#list ⇒ Object
Command to list all available Tasks.
It needs to use ‘Task.load_all` in order to load all the tasks available in the project before displaying them.
56 57 58 |
# File 'lib/maintenance_tasks/cli.rb', line 56 def list say(Task.load_all.map(&:name).sort.join("\n")) end |
#perform(name) ⇒ Object
Command to run a Task.
It instantiates a Runner and sends a run message with the given Task name. If a CSV file is supplied using the –csv option, an attachable with the File IO object is sent along with the Task name to run. If arguments are supplied using the –arguments option, these are also passed to run.
42 43 44 45 46 47 48 |
# File 'lib/maintenance_tasks/cli.rb', line 42 def perform(name) arguments = [:arguments] || {} task = Runner.run(name: name, csv_file: csv_file, arguments: arguments) say_status(:success, "#{task.name} was enqueued.", :green) rescue => error say_status(:error, error., :red) end |