76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/metacon/command.rb', line 76
def self.run
banner = "metacon\n"+
"MetaController version #{MetaCon::VERSION}\n" +
"Usage: metacon [COMMAND] [OPTIONS]"
options = {}
opts = OptionParser.new do |o|
o.version = MetaCon.version
o.banner = banner
o.separator ''
o.on('-q', '--[no-]quiet', 'Run command quietly'){|v| options[:verbose]= !v}
o.on('-h','--help', 'Show this message'){puts o; exit 0}
o.on('--version', 'Show version and exit'){puts MetaCon::VERSION; exit 0}
o.on('-s', '--[no-]shell-output', 'Outputs commands for evaluating in the current shell') do |v|
options[:shell]=v
end
o.separator ''
o.separator 'commands '
o.separator '------------------'
cmds = COMMANDS.map do |c,p|
args = p[:args].join(' ')
"#{(c.to_s + ' ' + args).ljust(36)} #{p[:desc]}"
end
o.separator cmds
end
rest = opts.parse(ARGV)
options[:shell] = false if options[:shell].nil?
options[:verbose] = true if options[:verbose].nil?
if rest.size == 0
puts(opts)
exit
end
command_key = rest.shift.strip.downcase
command = CMD_ALIASES[command_key.to_sym]
if command.nil?
cfail "Command #{command_key} not found. Use -h to see the list of commands."
exit 2
end
$cli = HighLine.new
$cli.extend(MetaCon::CLIHelpers)
$proj = nil
unless [:init].include?(command)
$proj = MetaCon::Project.new('./', options[:verbose])
unless $proj.valid || (command == :ps1)
$cli.cfail 'Not a metacon project. Use `metacon init`'
exit 5
end
end
command_info = COMMANDS.select{|k,v| k == command}[0][1]
command_info[:handler].send :handle, command, options, rest
end
|