Class: RailsInstaller::Command
- Inherits:
-
Object
- Object
- RailsInstaller::Command
- Defined in:
- lib/rails-installer/commands.rb
Overview
Parent class for command-line subcommand plugins for the installer. Each subclass must implement the command
class method and should provide help text using the help
method. Example (from Typo):
class SweepCache < RailsInstaller::Command
help "Sweep Typo's cache"
def self.command(installer, *args)
installer.sweep_cache
end
end
This implements a sweep_cache
command that Typo users can access by running ‘typo sweep_cache /some/path’.
Subcommands that need arguments should use both ‘help’ and ‘flag_help’, and then use the args
parameter to find their arguments. For example, the install
subcommand looks like this:
class Install < RailsInstaller::Command
help "Install or upgrade APPNAME in PATH."
flag_help "[VERSION] [KEY=VALUE]..."
def self.command(installer, *args)
version = nil
args.each do |arg|
...
end
end
end
Defined Under Namespace
Classes: Backup, Config, Install, Restart, Restore, Run, Start, Stop
Constant Summary collapse
- @@command_map =
{}
Class Method Summary collapse
-
.command(installer, *args) ⇒ Object
The
command
method implements this sub-command. - .commands ⇒ Object
-
.flag_help(text) ⇒ Object
flag_help
sets the help text for any arguments that this sub-command accepts. -
.flag_help_text ⇒ Object
Return the flag help text.
-
.help(text) ⇒ Object
help
sets the help text for this subcommand. -
.help_text ⇒ Object
Return the help text.
- .inherited(sub) ⇒ Object
Class Method Details
.command(installer, *args) ⇒ Object
The command
method implements this sub-command. It’s called by the command-line parser when the user asks for this sub-command.
39 40 41 |
# File 'lib/rails-installer/commands.rb', line 39 def self.command(installer, *args) raise "Not Implemented" end |
.commands ⇒ Object
72 73 74 |
# File 'lib/rails-installer/commands.rb', line 72 def self.commands @@command_map end |
.flag_help(text) ⇒ Object
flag_help
sets the help text for any arguments that this sub-command accepts. It defaults to ”.
45 46 47 |
# File 'lib/rails-installer/commands.rb', line 45 def self.flag_help(text) @flag_help = text end |
.flag_help_text ⇒ Object
Return the flag help text.
50 51 52 |
# File 'lib/rails-installer/commands.rb', line 50 def self.flag_help_text @flag_help || '' end |
.help(text) ⇒ Object
help
sets the help text for this subcommand.
55 56 57 |
# File 'lib/rails-installer/commands.rb', line 55 def self.help(text) @help = text end |
.help_text ⇒ Object
Return the help text.
60 61 62 |
# File 'lib/rails-installer/commands.rb', line 60 def self.help_text @help || '' end |
.inherited(sub) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/rails-installer/commands.rb', line 64 def self.inherited(sub) name = sub.to_s.gsub(/^.*::/,'').gsub(/([A-Z])/) do |match| "_#{match.downcase}" end.gsub(/^_/,'') @@command_map[name] = sub end |