解決したいこと
ターミナルでエラー文が表示される。
エラー文詳細
syntax error, unexpected end, expecting end-of-input (SyntaxError)
調べたこと
endが抜けいることで生じるエラー。
コード
```ruby
require 'optparse'
module Todo
class Command
module Options
def self.parse!(argv)
options = {}
sub_command_parsers = create_sub_command_parsers(options) command_parser = create_command_parser begin command_parser.order!(argv) options[:command] = argv.shift sub_command_parsers[options[:command]].parse!(argv) if %w(update delete).include?(options[:command]) raise ArgumentError, "#{options[:command]} id not foud." if argv.empty? options[:id] = Integer(argv.first) end rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e abort e.message end def create_sub_command_parsers(options) sub_command_parsers = Hash.new do |k, v| raise ArgumentError, "'#{v}' is not todo sub command." end sub_command_parsers['create'] = OptionParser.new do |opt| opt.on('-n VAL', '--name=VAL', 'task name') {|v| options[:name] = v} opt.on('-c VAL', '--content=VAL', 'task content'){|v| options[:content] = v} end sub_command_parsers['list'] = OptionParser.new do |opt| opt.on('-s VAL', '--status=VAL', 'list status') {|v| options[:status] = v} end sub_command_parsers['update'] = OptionParser.new do |opt| opt.on('-n VAL', '--name=VAL', 'update name') {|v| options[:name] = v} opt.on('-c VAL', '--content=VAL', 'update content') {|v| options[:content] = v} opt.on('-s VAL', '--status=VAL', 'update status') {|v| options[:status] = v} end sub_command_parsers['delete'] = OptionParser.new do |opt| end sub_command_parsers end def self.create_command_parser command_parser = OptionParser.new do |opt| sub_command_help = [ {name: 'create -n name -c content', summary: 'Create Todo Task'}, {name: 'update id -n name -c content -s status', summary: 'Update Todo Task'}, {name: 'list -s status', summary: 'List Todo Task'}, {name: 'delete id', summary: 'Create Todo Task'} ] opt.banner ="Usage: #{opt.program_name} [-h|--help] [-v|--version] <command> [<args>]" opt.separator '' opt.separator "#{opt.program_name} Available Commands:" sub_command_help.each do|command| opt.separator [opt.summary_indent, command[:name].ljust(40), command[:summary]].join('') end option.on_head('-h', '--help', 'Show this message') do |v| puts opt.help exit end opt.on_head('-v','--version','Show program version') do |v| opt.version = Todo::VERSION puts opt.ver exit end end end end end end
end
end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/04 04:39
2020/09/04 04:39
2020/09/04 04:42
2020/09/04 04:51
2020/09/04 04:55
2020/09/04 05:02
2020/09/04 05:04
2020/09/04 05:07