Class: Sashimi::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/sashimi/commands.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

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_nameObject (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

.parse!(args = ARGV) ⇒ Object



78
79
80
81
82
83
# File 'lib/sashimi/commands.rb', line 78

def self.parse!(args=ARGV)
  Command.new.parse!(args)
rescue Exception => e
  puts e.message
  exit 1
end

Instance Method Details

#optionsObject



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
49
50
51
52
53
54
# File 'lib/sashimi/commands.rb', line 12

def options
  OptionParser.new do |o|
    o.set_summary_indent('  ')
    o.banner =    "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(s) from known URL(s)."
    o.separator "  uninstall      Uninstall plugin(s) from local repository."
    o.separator "  update         Update installed plugin(s)."
    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 "  Update all installed plugins:"
    o.separator "    #{@script_name} update --all\n"
    o.separator "  Update plugin(s) already added to a Rails app:"
    o.separator "    #{@script_name} update --rails 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"
    o.separator "  Add installed plugin(s) to a Rails app:"
    o.separator "    #{@script_name} install --rails click-to-globalize\n"
  end
end

#parse!(args = ARGV) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sashimi/commands.rb', line 56

def parse!(args=ARGV)
  general, sub = split_args(args)
  options.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 options
    exit 1
  end
end

#split_args(args) ⇒ Object



71
72
73
74
75
76
# File 'lib/sashimi/commands.rb', line 71

def split_args(args)
  left = []
  left << args.shift while args[0] and args[0] =~ /^-/
  left << args.shift if args[0]
  return [left, args]
end