lib/img_dl/cli.rb in img_dl-0.0.3 vs lib/img_dl/cli.rb in img_dl-0.0.4

- old
+ new

@@ -31,11 +31,10 @@ NOT_MATCH = "Arguments not match!" class << self def not_match puts NOT_MATCH puts HELP - exit end def valid_save_path path FileUtils.mkdir_p path end @@ -52,17 +51,21 @@ puts HELP when '-version' puts VERSION else not_match + exit 1 end else save_path = args.pop url = args.pop options = {} options[:recursive] = args.delete '-r' - not_match if args.size.odd? + if args.size.odd? + not_match + exit 1 + end args.each_slice(2) do |opt,arg| case opt when '-ul' options[:url_limit_count] = arg.to_i when '-il' @@ -75,11 +78,11 @@ options[:prefix] = arg when '-in' options[:interval] = arg.to_i else puts "option '#{opt}' not support! please check out img_dl -h" - exit + exit 1 end end parser = ImgDl::Parser.new(url,save_path,options) Thread.start{parser.start;puts 'All done.';exit} parser @@ -105,17 +108,18 @@ end parser = ImgDl::Cli.run if parser at_exit do + ImgDl::Cli.prompt parser + puts until parser.error_urls.empty? puts parser.error_urls.shift - puts end - ImgDl::Cli.prompt parser end - $stdout.sync = true + loop do ImgDl::Cli.prompt parser - sleep 1 + $stdout.flush + sleep 3 end end