Skip to content

Commit

Permalink
Refactor move options
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcclimon committed Feb 2, 2014
1 parent 5ec405f commit 9baa3f7
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions lib/mr_poole/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,7 @@ def handle_draft
end

def handle_publish
options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
opts.on('-d', '--keep-draft', "Keep the draft post") do |d|
options.keep_draft = d
end
opts.on('-t', '--keep-timestamp', "Keep the existing timestamp") do |t|
options.keep_timestamp = t
end
end
opt_parser.parse! @params
options = do_move_options(:publish)

path = @params.first
@helper.publish_usage unless path
Expand All @@ -66,16 +57,7 @@ def handle_publish
end

def handle_unpublish
options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
opts.on('-p', '--keep-post', "Do not delete post") do |p|
options.keep_post = p
end
opts.on('-t', '--keep-timestamp', "Keep the existing timestamp") do |t|
options.keep_timestamp = t
end
end
opt_parser.parse! @params
options = do_move_options(:unpublish)

path = @params.first
@helper.unpublish_usage unless path
Expand Down Expand Up @@ -109,5 +91,28 @@ def do_creation_options
options
end

# pass a symbol, either :publish or :unpublish
def do_move_options(type)
options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
if type == :publish
opts.on('-d', '--keep-draft', "Keep draft post") do |d|
options.keep_draft = d
end
else
opts.on('-p', '--keep-post', "Do not delete post") do |p|
options.keep_post = p
end
end

opts.on('-t', '--keep-timestamp', "Keep existing timestamp") do |t|
options.keep_timestamp = t
end
end

opt_parser.parse! @params
options
end

end
end

0 comments on commit 9baa3f7

Please sign in to comment.