Skip to content

Commit

Permalink
Refactor: Extract #add_defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jun 1, 2019
1 parent 54cf3c2 commit d1fda31
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/cri/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,7 @@ def run_this(opts_and_args, parent_opts = {})
handle_errors_while { parser.run }
local_opts = parser.options
global_opts = parent_opts.merge(parser.options)

# Set defaults
all_opt_defns.each do |opt_defn|
key = (opt_defn.long || opt_defn.short).to_sym

next if opt_defn.default.nil?
next if global_opts.key?(key)

global_opts[key] = opt_defn.default
end
add_defaults(global_opts)

# Handle options
handle_options(local_opts)
Expand Down Expand Up @@ -442,5 +433,16 @@ def handle_errors_while
warn "#{name}: #{e.message}"
raise CriExitException.new(is_error: true)
end

def add_defaults(options)
all_opt_defns.each do |opt_defn|
key = (opt_defn.long || opt_defn.short).to_sym

next if opt_defn.default.nil?
next if options.key?(key)

options[key] = opt_defn.default
end
end
end
end

0 comments on commit d1fda31

Please sign in to comment.