class Setup::Command

Command-line interface for Setup.rb.

Public Class Methods

order() click to toggle source

Task names listed in order of information.

# File lib/setup/command.rb, line 24
def self.order
  @order ||= []
end
run(*argv) click to toggle source

Initialize and run.

# File lib/setup/command.rb, line 12
def self.run(*argv)
  new.run(*argv)
end
task(name, description) click to toggle source

Define a task.

# File lib/setup/command.rb, line 30
def self.task(name, description)
  tasks[name] = description
  order << name
end
tasks() click to toggle source

Hash of task => description.

# File lib/setup/command.rb, line 18
def self.tasks
  @tasks ||= {}
end

Public Instance Methods

configuration() click to toggle source

Setup configuration. This comes from the session object.

# File lib/setup/command.rb, line 119
def configuration
  @configuration ||= session.configuration
end
optparse_all(parser, options) click to toggle source

Setup options for all task.

# File lib/setup/command.rb, line 130
def optparse_all(parser, options)
  optparse_config(parser, options)
  optparse_compile(parser, options)
  optparse_install(parser, options)  # TODO: why was this remarked out ?
  #parser.on("-t", "--[no-]test", "run tests (default is --no-test)") do |val|
  #  configuration.no_test = val
  #end
  #parser.on("--[no-]doc", "generate ri/yri documentation (default is --doc)") do |val|
  #  configuration.no_doc = val
  #end
end
optparse_common(parser, options) click to toggle source

Common options for every task.

# File lib/setup/command.rb, line 227
def optparse_common(parser, options)
  parser.separator ""
  parser.separator "General options:"

  parser.on("-q", "--quiet", "Suppress output") do
    session.quiet = true
  end

  parser.on("-f", "--force", "Force operation") do
    session.force = true
  end

  parser.on("--trace", "--verbose", "Watch execution") do |val|
    session.trace = true
  end

  parser.on("--trial", "--no-harm", "Do not write to disk") do |val|
    session.trial = true
  end

  parser.on("--debug", "Turn on debug mode") do |val|
    $DEBUG = true
  end

  parser.separator ""
  parser.separator "Inform options:"

  # Tail options (eg. commands in option form)
  parser.on_tail("-h", "--help", "display this help information") do
    #puts help
    puts parser
    exit
  end

  parser.on_tail("--version", "-v", "Show version") do
    puts File.basename($0) + ' v' + Setup::VERSION #Version.join('.')
    exit
  end

  parser.on_tail("--copyright", "Show copyright") do
    puts Setup::COPYRIGHT #opyright
    exit
  end
end
optparse_compile(parser, options) click to toggle source
# File lib/setup/command.rb, line 183
def optparse_compile(parser, options)
end
optparse_config(parser, options) click to toggle source

Setup options for config task.

# File lib/setup/command.rb, line 144
def optparse_config(parser, options)
  parser.separator ""
  parser.separator "Configuration options:"
  #parser.on('--reset', 'reset configuration to default settings') do
  #  session.reset = true
  #end
  configuration.options.each do |args|
    args = args.dup
    desc = args.pop
    type = args.pop
    name, shortcut = *args
    #raise ArgumentError unless name, type, desc
    optname = name.to_s.gsub('_', '-')
    case type
    when :bool
      if optname.index('no-') == 0
        optname = "[no-]" + optname.sub(/^no-/, '')
        opts = shortcut ? ["-#{shortcut}", "--#{optname}", desc] : ["--#{optname}", desc]
        parser.on(*opts) do |val|
          configuration.__send__("#{name}=", !val)
        end
      else
        optname = "[no-]" + optname.sub(/^no-/, '')
        opts = shortcut ? ["-#{shortcut}", "--#{optname}", desc] : ["--#{optname}", desc]
        parser.on(*opts) do |val|
          configuration.__send__("#{name}=", val)
        end
      end
    else
      opts = shortcut ? ["-#{shortcut}", "--#{optname} #{type.to_s.upcase}", desc] :
                        ["--#{optname} #{type.to_s.upcase}", desc]
      parser.on(*opts) do |val|
        configuration.__send__("#{name}=", val)
      end
    end
  end
end
optparse_header(parser, options) click to toggle source
# File lib/setup/command.rb, line 124
def optparse_header(parser, options)
  parser.banner = "USAGE: #{File.basename($0)} [command] [options]"
end
optparse_install(parser, options) click to toggle source

Setup options for install task.

# File lib/setup/command.rb, line 188
def optparse_install(parser, options)
  parser.separator ''
  parser.separator 'Install options:'
  # install prefix overrides target prefix when installing
  parser.on('--prefix PATH', 'install to alternate root location') do |val|
    configuration.install_prefix = val
  end
  # type can override config
  parser.on('--type TYPE', "install location mode (site,std,home)") do |val|
    configuration.type = val
  end
  # test can be override config
  parser.on('-t', '--[no-]test', "run pre-installation tests") do |bool|
    configuration.test = bool
  end
end
print_header() click to toggle source

Output Header.

TODO: This is not yet used. It might be nice to have, but not sure what it should contain or look like.

run(*argv) click to toggle source

Run command.

# File lib/setup/command.rb, line 47
def run(*argv)
  ARGV.replace(argv) unless argv.empty?

  #session = Session.new(:io=>$stdio)
  #config  = session.configuration

  task = ARGV.find{ |a| a !~ /^[-]/ }
  task = 'all' unless task

  #task = 'doc' if task == 'document'

  unless task_names.include?(task)
    $stderr.puts "Not a valid task -- #{task}"
    exit 1
  end

  parser  = OptionParser.new
  options = {}

  parser.banner = "Usage: #{File.basename($0)} [TASK] [OPTIONS]"

  optparse_header(parser, options)
  case task
  when 'config'
    optparse_config(parser, options)
  when 'compile'
    optparse_compile(parser, options)
  when 'install'
    optparse_install(parser, options)
  when 'all'
    optparse_all(parser, options)
  end
  optparse_common(parser, options)

  begin
    parser.parse!(ARGV)
  rescue OptionParser::InvalidOption
    $stderr.puts $!.to_s.capitalize
    exit 1
  end

  # This ensures we are in a project directory.
  rootdir = session.project.rootdir

  print_header

  begin
    $stderr.puts "(#{RUBY_ENGINE} #{RUBY_VERSION} #{RUBY_PLATFORM})"
  rescue
    $stderr.puts "(#{RUBY_VERSION} #{RUBY_PLATFORM})"
  end

  begin
    session.__send__(task)
  rescue Error => err
    raise err if $DEBUG
    $stderr.puts $!.message
    $stderr.puts "Try 'setup.rb --help' for detailed usage."
    abort $!.message #exit 1
  end

  puts unless session.quiet?
end
session() click to toggle source

Setup session.

# File lib/setup/command.rb, line 113
def session
  @session ||= Session.new(:io=>$stdout)
end
task_names() click to toggle source

List of task names.

# File lib/setup/command.rb, line 277
def task_names
  #self.class.order
  self.class.tasks.keys
end