Class: ItunesController::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/itunesController/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(appName) ⇒ Application

Returns a new instance of Application.



34
35
36
37
38
# File 'lib/itunesController/application.rb', line 34

def initialize(appName)
    @appName = appName
    @options = {}
    @options[:logFile] = nil
end

Instance Method Details

#checkAppOptionsObject



119
120
# File 'lib/itunesController/application.rb', line 119

def checkAppOptions()
end

#checkOptionsObject

Used to check the command line options are valid



66
67
68
# File 'lib/itunesController/application.rb', line 66

def checkOptions
    checkAppOptions
end

#displayUsageObject

Used to display the command line useage



51
52
53
54
55
# File 'lib/itunesController/application.rb', line 51

def displayUsage()
    puts("Usage: "+@appName+" [options]")
    puts("")
    puts(genericOptionDescription())
end

#execObject



105
106
107
108
109
110
# File 'lib/itunesController/application.rb', line 105

def exec()
    parseOptions
    controllerCreator = createController()
    execApp(controllerCreator)
    #controller.close()
end

#execApp(controllerCreator) ⇒ Object



122
123
124
# File 'lib/itunesController/application.rb', line 122

def execApp(controllerCreator)
    raise "ERROR: Your trying to instantiate an abstract class"
end

#genericOptionDescriptionObject



40
41
42
43
44
45
46
47
48
# File 'lib/itunesController/application.rb', line 40

def genericOptionDescription()
    result=[]
    result.push("Specific options:")
    result.push("    -f, --log_file FILE              Optional paramter used to log messages to")
    result.push("    -l, --log_config LEVEL           Optional paramter used to log level [DEBUG|INFO|WARN|ERROR]")               
    result.push("    -v, --version                    Display version of the application")
    result.push("    -h, --help                       Display this screen")
    return result.join("\n")
end

#getOptionsObject



112
113
114
# File 'lib/itunesController/application.rb', line 112

def getOptions()
    return @options
end

#parseAppOptions(opts) ⇒ Object



116
117
# File 'lib/itunesController/application.rb', line 116

def parseAppOptions(opts)
end

#parseOptionsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/itunesController/application.rb', line 70

def parseOptions
    optparse = OptionParser.new do|opts|
        opts.banner = "Usage: "+@appName+" [options]"
        opts.separator ""
        opts.separator "Specific options:"

        opts.on('-f','--log_file FILE','Optional paramter used to log messages to') do |value|
            @options[:logFile] = value
            ItunesController::ItunesControllerLogging::setLogFile(@options[:logFile])
        end
        opts.on('-l','--log_config LEVEL','Optional paramter used to log level [DEBUG|INFO|WARN|ERROR]') do |value|
            @options[:logConfig] = value
            ItunesController::ItunesControllerLogging::setLogLevelFromString(@options[:logConfig])
        end
        parseAppOptions(opts)

        opts.on_tail( '-v', '--version', 'Display version of the application' ) do
            puts "itunes-remote-control-server "+ItunesController::VERSION
            puts "Copyright (C) 2012 John-Paul Stanford"
            puts "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>."
            puts "This is free software: you are free to change and redistribute it."
            puts "There is NO WARRANTY, to the extent permitted by law."
            puts ""
            puts "Authors: John-Paul Stanford <[email protected]>"
            puts "Website: http://code.google.com/p/itunes-remote-control-server/"
        end
        opts.on_tail( '-h', '--help', 'Display this screen' ) do
            puts opts
            exit
        end
    end
    optparse.parse!
    checkOptions()
end

#usageError(message) ⇒ Object

Used to display a error message and the command line usesage

Parameters:

  • message (String)

    The error message



59
60
61
62
63
# File 'lib/itunesController/application.rb', line 59

def usageError(message)
    $stderr.puts "ERROR: "+message
    displayUsage()
    exit(1)
end