lib/dvdprofiler2xbmc/views/cli.rb in royw-dvdprofiler2xbmc-0.0.6 vs lib/dvdprofiler2xbmc/views/cli.rb in royw-dvdprofiler2xbmc-0.0.8
- old
+ new
@@ -1,7 +1,8 @@
+require File.join(File.dirname(__FILE__), 'config_editor')
require 'commandline/optionparser'
-include CommandLine
+# include CommandLine
# Command Line interface for the Dvdprofiler2Xbmc application.
# All application output is via AppConfig[:logger] so we have
# to set up the logger here.
# Also handle the command line options.
@@ -34,14 +35,25 @@
logger = setup_logger
# parse the command line
options = setup_parser()
od = options.parse(arguments)
+ run_editor = !AppConfig.exist?
setup_app_config(od, logger)
+ run_editor = true unless AppConfig.valid?
- unless od["--help"] || od["--version"]
+ logger.info(AppConfig.to_s) if od["--show_config"]
+
+ if run_editor || od["--edit_config"]
+ editor = ConfigEditor.new
+ editor.execute
+ end
+
+ skip_execution = false
+ %w(--help --version --show_config --edit_config).each {|flag| skip_execution = true if od[flag] || run_editor}
+ unless skip_execution
# create and execute class instance here
app = DvdProfiler2Xbmc.instance
app.execute
app.report.each {|line| AppConfig[:logger].info line}
end
@@ -63,11 +75,10 @@
# then we run reinitialize_logger again to modify the logger for any logging options from the config files
reinitialize_logger(logger, od["--quiet"], od["--debug"])
AppConfig.load
AppConfig.save
- AppConfig[:imdb_query] = !od["--no_imdb_query"]
AppConfig[:logfile] = od['--output'] if od['--output']
AppConfig[:logfile_level] = od['--output_level'] if od['--output_level']
reinitialize_logger(logger, od["--quiet"], od["--debug"])
AppConfig[:do_update] = !od["--reports"]
@@ -78,11 +89,11 @@
end
# Setup the command line option parser
# Returns:: OptionParser instances
def self.setup_parser()
- options = OptionParser.new()
+ options = CommandLine::OptionParser.new()
# flag options
[
{
:names => %w(--version -v),
@@ -93,14 +104,18 @@
:names => %w(--help -h),
:opt_found => lambda {Log4r::Logger['dvdprofiler2xbmc'].info{options.to_s}},
:opt_description => "This usage information"
},
{
- :names => %w(--no_imdb_query -n),
- :opt_description => 'Do not query IMDB.com'
+ :names => %w(--show_config -s),
+ :opt_description => "This is the current configuration information"
},
{
+ :names => %w(--edit_config -e),
+ :opt_description => "Edit the current configuration information"
+ },
+ {
:names => %w(--quiet -q),
:opt_description => 'Display error messages only'
},
{
:names => %w(--debug -d),
@@ -112,28 +127,28 @@
},
{
:names => %w(--reports -r),
:opt_description => 'Display reports only. Do not do any updates.'
}
- ].each { |opt| options << Option.new(:flag, opt) }
+ ].each { |opt| options << CommandLine::Option.new(:flag, opt) }
# non-flag options
[
{
:names => %w(--output -o),
:argument_arity => [1,1],
:arg_description => 'logfile',
:opt_description => 'Write log messages to file. Default = no log file',
- :opt_found => OptionParser::GET_ARGS
+ :opt_found => CommandLine::OptionParser::GET_ARGS
},
{
:names => %w(--output_level -l),
:argument_arity => [1,1],
:arg_description => 'level',
:opt_description => 'Output logging level: DEBUG, INFO, WARN, ERROR. Default = INFO',
- :opt_found => OptionParser::GET_ARGS
+ :opt_found => CommandLine::OptionParser::GET_ARGS
}
- ].each { |opt| options << Option.new(opt) }
+ ].each { |opt| options << CommandLine::Option.new(opt) }
options
end
# Initial setup of logger