class RBT::Installer::Shell

Constants

DEFAULT_SHOW_N_PROGRAMS_THAT_WERE_LAST_UPDATED
#

DEFAULT_SHOW_N_PROGRAMS_THAT_WERE_LAST_UPDATED

#

Public Class Methods

[](i = '') click to toggle source
#

RBT::Installer::Shell[]

#
# File lib/rbt/shell/shell.rb, line 365
def self.[](i = '')
  new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/shell/shell.rb, line 39
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  case i
  when :dont_run_yet
    run_already = false
    @run_the_main_loop = false
    i = nil
  end
  set_input(i)
  case run
  when :dont_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

display_colourized_comment(i) click to toggle source
#

display_colourized_comment

Let class Colours handle the colour there, via eparse().

#
# File lib/rbt/shell/shell.rb, line 295
def display_colourized_comment(i)
  eparse(i)
end
do_autocompile() click to toggle source
#

do_autocompile

#
# File lib/rbt/shell/shell.rb, line 244
  def do_autocompile
    require 'rbt/requires/swift_version.rb'
    e
    e 'The method '+orange('do_autocompile()')+' will attempt to '\
      'compile several programs.'
    e
    e 'The target directory is currently hardcoded towards `'+sdir('/Programs/')+'`.'
    e 'This will change at a later time, to allow any directory as the main'
    e '--prefix= in use.'
    e 
    e 'This method will first check the locally available latest version of'
    e 'the programs that are to be compiled.'
    e
    e 'Compilation will only happen if the program in the Cookbooks directory'
    e 'is more recent than the locally available program.'
    e
    array = %i( sed awk )
    array.each {|this_program|
      version_in_the_cookbooks_file = RBT.return_version_of(this_program)
e 'TODO'
e 'The local version of '+this_program.to_s+' is: '+
   sfancy(version_in_the_cookbooks_file)
e 'We still have to compare this to the local version available on'
e 'this computer.'
    }
  end
do_compile_this_program(i) click to toggle source
#

do_compile_this_program

#
# File lib/rbt/shell/shell.rb, line 159
def do_compile_this_program(i)
  i.strip!
  if i.include? ' '
    # ===================================================================== #
    # In this case we need to determine what the user wants.
    # ===================================================================== #
    splitted = i.split(' ')
    first = splitted.first
    last  = splitted.last
    case last
    # ===================================================================== #
    # === trad
    # ===================================================================== #
    when /^trad/i
      notify_the_user_that_this_program_will_be_compiled_next(first)
      RBT::Installer.new(first) {{ prefix: 'trad' }}
      return
    end
  end
  notify_the_user_that_this_program_will_be_compiled_next(i)
  if @use_this_prefix
    _ = @use_this_prefix
    case _
    # ===================================================================== #
    # Handle AppDir prefixes next.
    # ===================================================================== #
    when :app_dir, :appdir
      _ = programs_dir?+i.to_s.capitalize+'/'+
          return_version_of_this_program(i)+'/' # ← Add the program-version here.
    end
    RBT::Installer.new(i) {{ prefix: _ }}
  else
    RBT::Installer.new(i)
  end
end
edit_this_file( i = @all_arguments ) click to toggle source
#

edit_this_file (edit tag)

This method can be used to quickly edit a .yml file from within the compile-shell.

#
# File lib/rbt/shell/shell.rb, line 314
def edit_this_file(
    i = @all_arguments
  )
  if i.is_a? Array
    i.each {|entry| edit_this_file(entry) }
  else
    i = i.dup if i.frozen?
    i << '.yml' unless i.end_with? '.yml'
    unless i.include? '/'
      i.prepend RBT.individual_cookbooks_directory?
    end
    i.prepend('nano ')
    esystem i
  end
end
input?() click to toggle source
#

input?

#
# File lib/rbt/shell/shell.rb, line 103
def input?
  @input
end
menu(i) { || ... } click to toggle source
#

menu (menu tag)

#
notify_the_user_that_input_can_be_passed_in_now() click to toggle source
#

notify_the_user_that_input_can_be_passed_in_now

#
# File lib/rbt/shell/shell.rb, line 110
def notify_the_user_that_input_can_be_passed_in_now
  opnn { :no_trailing }
  e
  e
  e 'Type your given input next (or pass "'+
    steelblue('help')+'" for help options):'
end
notify_the_user_that_this_program_will_be_compiled_next(i) click to toggle source
#

notify_the_user_that_this_program_will_be_compiled_next

This is just a notification - for the actual compile-action you have to add the code after an invocation to this method here.

#
# File lib/rbt/shell/shell.rb, line 351
def notify_the_user_that_this_program_will_be_compiled_next(i)
  e "Next compiling `#{sfancy(i.strip)}`."
end
obtain_user_input() click to toggle source
#

obtain_user_input

#
# File lib/rbt/shell/shell.rb, line 121
def obtain_user_input
  if @can_we_use_readline
    @user_input = Readline.readline('', true)
    # ===================================================================== #
    # Next ignore empty input.
    # ===================================================================== #
    Readline::HISTORY.pop if @user_input.strip.empty?
  else # else use $stdin
    @user_input = $stdin.gets.chomp
  end
end
query_the_prefix_in_use() click to toggle source
#

query_the_prefix_in_use

#
# File lib/rbt/shell/shell.rb, line 198
def query_the_prefix_in_use
  prefix = '/usr/'
  prefix = @use_this_prefix if @use_this_prefix
  prefix
end
remove_this_entry_from_the_database(i) click to toggle source
#

remove_this_entry_from_the_database

#
# File lib/rbt/shell/shell.rb, line 274
def remove_this_entry_from_the_database(i)
  database_location = rbt_logs?+'database_storing_compile_times.yml'
  if File.exist? database_location
    old_dataset = YAML.load_file(database_location)
    old_dataset.reject! {|key, value|
      key == i
    }
    e 'Storing the dataset into the file '+sfile(database_location)+'.'
    write_what_into(
      YAML.dump(old_dataset), database_location
    )
  else
    opnn; no_file_exists_at(database_location)
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/shell/shell.rb, line 61
def reset
  super()
  begin
    require 'readline'
  rescue LoadError; end
  infer_the_namespace
  # ======================================================================= #
  # === @can_we_use_readline
  # ======================================================================= #
  @can_we_use_readline = Object.const_defined? :Readline
  # ======================================================================= #
  # If the following variable is set to true, then the Shell will
  # ask for user-input. This is the default.
  # ======================================================================= #
  @run_the_main_loop = true
  # ======================================================================= #
  # === @use_this_prefix
  # ======================================================================= #
  @use_this_prefix = nil
end
return_compile_time() click to toggle source
#

return_compile_time

#
# File lib/rbt/shell/shell.rb, line 302
def return_compile_time
  RBT::Installer.new(
    nil, :dont_run_yet
  ).return_compile_time_statistics
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/shell/shell.rb, line 358
def run
  run_main_loop if @run_the_main_loop
end
run_main_loop() click to toggle source
#

run_main_loop

#
# File lib/rbt/shell/shell.rb, line 136
def run_main_loop
  notify_the_user_that_input_can_be_passed_in_now
  loop {
    # ===================================================================== #
    # First, we have to obtain the user input.
    # ===================================================================== #
    obtain_user_input
    i = @user_input
    if i.include? ' '
      splitted = i.split(' ')
      @all_arguments = splitted[1 .. -1].join(' ').strip
      i = splitted.first
    else
      @all_arguments = nil
    end
    a = @all_arguments
    menu(i) { a }
  }
end
set_input(i = '') click to toggle source
#

set_input

#
# File lib/rbt/shell/shell.rb, line 94
def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
end
set_use_this_prefix(i) click to toggle source
#

set_use_this_prefix

#
# File lib/rbt/shell/shell.rb, line 85
def set_use_this_prefix(i)
  i = i.to_s.dup if i.frozen?
  i << '/' unless i.end_with? '/'
  @use_this_prefix = i
end
show_available_programs() click to toggle source
#

show_available_programs

#
# File lib/rbt/shell/shell.rb, line 207
def show_available_programs
  available_programs?.each_with_index {|this_program, index| index += 1
    e "#{sfancy(index)} #{simp(this_program)}"
  }
end
show_compile_time() click to toggle source
#

show_compile_time

To invoke this method from the commandline, do:

RBT::Installer::Shell.new
#
# File lib/rbt/shell/shell.rb, line 338
def show_compile_time
  RBT::Installer.new(
    nil, :dont_run_yet
  ).show_compile_time_statistics
end
show_help() click to toggle source
#

show_help (help tag)

#
# File lib/rbt/shell/help.rb, line 16
def show_help
  opne 'These help options are available:'
  e
  display_colourized_comment '  show_compile_time     # (1) show the '\
    'compile-time statistics (also aliased to '+
    slateblue('stats?')+
    teal(')')+
    rev
  display_colourized_comment '  available?            # (2) show '\
    'the available programs'
  display_colourized_comment '  last_update?          # (3) show '\
    'when the last update of the last 100 programs happened'
  display_colourized_comment '  autocompile           # (4) try to '\
    'autocompile several programs'
  display_colourized_comment '  edit                  # (5) to edit '\
    'a .yml file (recipe)'
  display_colourized_comment '  remove_entry aclocal  # (6) remove '\
    'the entry "aclocal" from the database of compiled programs'
  e
  e 'You can also enable AppDir prefixes for compilation via'
  e '"nontrad".'
end
show_last_update( n_last_programs = :default ) click to toggle source
#

show_last_update

#
# File lib/rbt/shell/shell.rb, line 216
def show_last_update(
    n_last_programs = :default
  )
  if n_last_programs.is_a? Array
    n_last_programs = n_last_programs.first
  end
  case n_last_programs
  when :default,
       nil
    n_last_programs = DEFAULT_SHOW_N_PROGRAMS_THAT_WERE_LAST_UPDATED # Default value.
  end
  n_last_programs = n_last_programs.to_i if n_last_programs.is_a? String
  array = ::RBT::Cookbooks::ShowLastUpdated.dataset?
  result = array[0 .. (n_last_programs - 1)] # -1 because Array start at 0.
  result.each_with_index {|inner_array, index| index += 1 # ["alock", "01 Jul 2011", 55]
    name_of_the_program = inner_array.first
    last_updated_when   = inner_array[1]
    padded_index = ("#{index})").rjust(4,' ')
    e simp(padded_index)+' '+sfancy((name_of_the_program).ljust(30))+
      steelblue(
        'Last updated: '
      )+orange(last_updated_when)
  }
end