Created
April 1, 2010 10:32
-
-
Save alainravet/351637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# with Daemons, extract the params. for the daemonized process | |
# | |
# Input : | |
# ["run", "--", "--source=/tmp/sour", "--archive=/tmp/arch"] | |
# ^ ^^^^^^^^^ ^^^^^^^^^ | |
# | :source :archive | |
# the separator | |
# | |
# Output : | |
# {:source=>"/tmp/sour", :archive=>"/tmp/arch"} | |
# | |
def extract_process_params(argv) | |
return {} unless argv.include?('--') | |
idx = argv.index('--') | |
argv_useful = argv[idx+1..-1] | |
# argv_useful = ["--source=/tmp/sour", "--archive=/tmp/arch"] | |
choices_a = (argv_useful || []).collect do |p| | |
if p =~ /--source=(.*)/ | |
[:source, $1] | |
elsif p =~ /--archive=(.*)/ | |
[:archive, $1] | |
end | |
end.compact | |
# choices_a = [[:source, "/tmp/sour"], [:archive, "/tmp/arch"]] | |
choices_h = Hash[*choices_a.flatten] | |
# {:source=>"/tmp/sour", :archive=>"/tmp/arch"} | |
end | |
argv = ["run", "--", "--source=/tmp/sour", "--archive=/tmp/arch"] | |
puts extract_process_params(argv).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment