Class: Sashimi::Commands::Command
- Inherits:
-
Object
- Object
- Sashimi::Commands::Command
- Defined in:
- lib/sashimi/commands.rb
Instance Attribute Summary collapse
-
#script_name ⇒ Object
readonly
Returns the value of attribute script_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #options ⇒ Object
- #parse!(args = ARGV) ⇒ Object
- #split_args(args) ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
8 9 10 |
# File 'lib/sashimi/commands.rb', line 8 def initialize @script_name = File.basename($0) end |
Instance Attribute Details
#script_name ⇒ Object (readonly)
Returns the value of attribute script_name.
6 7 8 |
# File 'lib/sashimi/commands.rb', line 6 def script_name @script_name end |
Class Method Details
Instance Method Details
#options ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sashimi/commands.rb', line 12 def OptionParser.new do |o| o.set_summary_indent(' ') o. = "Usage: #{@script_name} [OPTIONS] command" o.define_head "Rails plugin manager." o.separator "" o.separator "GENERAL OPTIONS" o.on("-v", "--verbose", "Turn on verbose output.") { |$verbose| } o.on("-h", "--help", "Show this help message.") { puts o; exit } o.separator "" o.separator "COMMANDS" o.separator " install Install plugin from known URL." o.separator " uninstall Uninstall plugin from local repository." o.separator " update Update an installed plugin." o.separator " list List all installed plugins." o.separator " add Add installed plugin(s) to a Rails app." o.separator "" o.separator "EXAMPLES" o.separator " Install a plugin from a subversion URL:" o.separator " #{@script_name} install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n" o.separator " Install a plugin from a git URL:" o.separator " #{@script_name} install git://github.com/jodosha/click-to-globalize.git\n" o.separator " Uninstall a plugin:" o.separator " #{@script_name} uninstall continuous_builder\n" o.separator " Update a plugin:" o.separator " #{@script_name} update click-to-globalize\n" o.separator " List all installed plugins:" o.separator " #{@script_name} list\n" o.separator " Add installed plugin(s) to a Rails app:" o.separator " #{@script_name} add click-to-globalize\n" end end |
#parse!(args = ARGV) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sashimi/commands.rb', line 50 def parse!(args=ARGV) general, sub = split_args(args) .parse!(general) command = general.shift if command =~ /^(install|uninstall|update|list|add)$/ command = Commands.const_get(command.capitalize).new(self) command.parse!(sub) else puts "Unknown command: #{command}" puts exit 1 end end |
#split_args(args) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/sashimi/commands.rb', line 65 def split_args(args) left = [] left << args.shift while args[0] and args[0] =~ /^-/ left << args.shift if args[0] return [left, args] end |