Baguette::Configuration.option_parser
This commit is contained in:
parent
b8d5493f1c
commit
7c1ab2f3cc
1 changed files with 52 additions and 0 deletions
|
@ -39,6 +39,58 @@ class Baguette::Configuration
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Read options from the CLI.
|
||||||
|
# We currently want to know:
|
||||||
|
# - the program verbosity
|
||||||
|
# - the configuration file to use
|
||||||
|
# - if the configuration files should be ignored
|
||||||
|
# - if this is just a simulation (used to print configuration then quit)
|
||||||
|
def self.option_parser
|
||||||
|
simulation = no_configuration = configuration_file = nil
|
||||||
|
|
||||||
|
help = false
|
||||||
|
|
||||||
|
OptionParser.parse do |parser|
|
||||||
|
parser.banner = "usage: #{PROGRAM_NAME} [-ns][-c configuration-file]"
|
||||||
|
|
||||||
|
parser.on "-s", "--simulation",
|
||||||
|
"Print configuration then quit." do
|
||||||
|
simulation = true
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-n", "--no-configuration",
|
||||||
|
"No configuration file should be read." do
|
||||||
|
no_configuration = true
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-v verbosity", "--verbosity level",
|
||||||
|
"Verbosity level. From 0 to 3. Default: 1" do |v|
|
||||||
|
Baguette::Context.verbosity = v.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-c file", "--configuration file",
|
||||||
|
"Configuration file." do |file|
|
||||||
|
configuration_file = file
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.invalid_option do |arg|
|
||||||
|
# Do not print anything: we only check for configuration file stuff.
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-h", "--help", "Show this help" do
|
||||||
|
Baguette::Log.warning "for the first option parsing!"
|
||||||
|
puts parser
|
||||||
|
help = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Options are removed once read from the ARGV array, but we want to propagate
|
||||||
|
# this particular option to print the second set of options.
|
||||||
|
ARGV.push "-h" if help
|
||||||
|
|
||||||
|
return simulation, no_configuration, configuration_file
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Baguette::Log
|
class Baguette::Log
|
||||||
|
|
Loading…
Add table
Reference in a new issue