optionparser pass an array to ruby file -


i have trouble passing arguments ruby file. ie,

optionparser.new |opts|   opts.banner = 'usage: mp3split.rb [options]'    opts.on('-f', '--filename fname1,fname2,fname3', array, 'absolute or relative pathes file') { |f| options[:filenames] = f } end.parse! 

this approach requires me write commands:

ruby mp3split.rb --filename fursov_13.mp3,fursov_14.mp3,fursov_14_2.mp3,fursov_15.mp3,fursov_16.mp3,fursov_17.mp3 

but want array this:

ruby mp3split.rb --filename fursov_13.mp3 fursov_14.mp3 fursov_14_2.mp3 fursov_15.mp3 fursov_16.mp3 fursov_17.mp3 

how can implement functionality? can't find helpful in docs.

with optionparser can’t. there workaround, though, when there list need handle way , won’t pass other arguments script. optionparser splits input spaces before processes it. unkeyed arguments remain in argv global constant after parsing. assuming described above met, here go:

optionparser.new |opts|   options[:filenames] = []   opts.banner = 'usage: mp3split.rb [options]'           opts.on('-f', '--filename fname1 fname2 fname3', array,            'absolute or relative pathes file') |f|     options[:filenames] |= [*f]   end end.parse!  options[:filenames] |= argv 

i apparently fixed glitch within code: options[:filenames] should appended not overwritten on every occurence of -f switch, optionparser supports script -f f1 -f f2 -f f3.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -