class RBT::Commandline

Public Class Methods

new(i) click to toggle source
#

initialize

#
# File lib/rbt/commandline/commandline_interface.rb, line 36
def initialize(i)
  reset
  i = [i].flatten.compact
  RBT.set_commandline_options(i) # <- Keep a reference to the commandline-options.
  # ======================================================================= #
  # Compile existing files next, if passed in as an argument.
  # ======================================================================= #
  if i.any? {|file| File.exist? file } and !i.any? {|entry| entry.include?('--extract') }
    # ===================================================================== #
    # Shortcut for batch-compiling several programs in one go. If the
    # --extract command is used then this will be skipped.
    # ===================================================================== #
    selection = i.select {|entry| File.exist? entry }
    do_compile_these_programs(
      selection
    )
    i = i - selection
  end
  # ======================================================================= #
  # In this case, pass through the menu interface.
  # ======================================================================= #
  menu(i)
  unless @the_menu_interface_already_handled_the_user_input
    arguments = i[1..-1]
    RBT::Compile.new(i.first) {{
      commandline_arguments: arguments
    }}
  end
end

Public Instance Methods

do_compile_these_programs(i) click to toggle source
#

do_compile_these_programs

This method can be used to compile

#
# File lib/rbt/commandline/commandline_interface.rb, line 124
def do_compile_these_programs(i)
  i = [i].flatten
  RBT::Compile.new(i)
end
menu(i) click to toggle source
#

menu (menu tag)

#
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/commandline/commandline_interface.rb, line 69
def reset
  super()
  @the_menu_interface_already_handled_the_user_input = false
  @namespace = NAMESPACE
end
set_user_input_was_handled_already() click to toggle source
#

set_user_input_was_handled_already

#
# File lib/rbt/commandline/commandline_interface.rb, line 78
def set_user_input_was_handled_already
  @the_menu_interface_already_handled_the_user_input = true
end
try_to_compile_these_programs(i)
try_to_compile_this_program(i) click to toggle source
#

try_to_compile_this_program

This method will first check whether we can try to compile the given program at hand, before delegating towards class RBT::Compile.

#
# File lib/rbt/commandline/commandline_interface.rb, line 88
def try_to_compile_this_program(i)
  if i.is_a? Array
    i.each {|entry| try_to_compile_this_program(entry) }
  else
    can_we_compile = true
    # ===================================================================== #
    # Check whether the given input is a program. First, we do so
    # without checking for abbreviations.
    # ===================================================================== #
    if is_this_program_included?(i)
      opnn; e 'The program '+sfancy(i)+' is included.'
    # ===================================================================== #
    # Check if it is an abbreviation.
    # ===================================================================== #
    elsif is_this_program_included?(i, :with_abbreviations)
      points_at = RBT.abbreviations?[i] # <- And use the abbreviation in this case, too.
      opnn; e 'The program '+sfancy(i)+' is included. It '\
              'is an abbreviation pointing '
      opnn; e 'towards the program '+sfancy(points_at)+'.'
      i = points_at
    else
      e 'The program '+sfancy(i)+' is '+swarn('NOT')+' included.'
      can_we_compile = false
    end
    if can_we_compile
      opnn; e 'We can compile it.'
      do_compile_these_programs(i)
    end
  end
end