class Cookbooks::ShowConfigurationOptions

Constants

DEFAULT_PROGRAM_NAME
#

DEFAULT_PROGRAM_NAME

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( for_this_program = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 45
def initialize(
    for_this_program = nil,
    run_already      = true
  )
  reset
  set_commandline_arguments(for_this_program) # This is also a backup-copy.
  set_for_this_program(for_this_program)
  run if run_already
end

Public Instance Methods

data()
Alias for: data?
data?() click to toggle source
#

data?

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 211
def data?
  @data
end
Also aliased as: data
dataset?() click to toggle source
#

dataset?

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 172
def dataset?
  @dataset
end
determine_cookbook() click to toggle source
#

#determine_cookbook

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 165
def determine_cookbook
  @dataset = ::Cookbooks::Cookbook.new(this_program?)
end
feedback_help_then_exit() click to toggle source
#

#feedback_help_then_exit

This will show some help options, then exit.

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 195
def feedback_help_then_exit
  opnn; e 'You can use the current working directory via PWD.'
  opnn; Colours.eparse 'XORG # Set the xorg buffer here as well, silently.'
  exit
end
find_cookbook_alias_for(i) click to toggle source
#

#find_cookbook_alias_for

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 353
def find_cookbook_alias_for(i)
  ::Cookbooks.find_cookbook_alias_for(i)
end
found?() click to toggle source
#

found?

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 179
def found?
  @dataset.found?
end
input?()
Alias for: this_program?
insert_prefix_to_use() click to toggle source
#

#insert_prefix_to_use

This will insert the prefix that we will use. The prefix is usually /usr but it can also be an AppDir prefix such as /Programs/Htop/2.0.2.

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 324
def insert_prefix_to_use
  _ = ' --prefix='
  use_this_prefix = prefix_to_use?.to_s # Better as String.
  if use_this_prefix.include?(programs_dir?) and
     @commandline_arguments.is_a?(Array) and
     @commandline_arguments.empty?
    # ===================================================================== #
    # This means that the user provided no arguments, thus we will use
    # the current working directory as our assumed input.
    # ===================================================================== #
    splitted = use_this_prefix.split('/')
    # program_version = splitted.last # This is usually the program version.
    # ===================================================================== #
    # Now we will simply use the current working directory as version,
    # if it matches a specific regex.
    # ===================================================================== #
    assumed_version_of_the_working_directory = File.basename(Dir.pwd)
    new_version = ::ProgramInformation.return_program_version(assumed_version_of_the_working_directory)
    splitted[-1] = new_version
    use_this_prefix = splitted.join('/')
  end
  _ = _.dup if _.frozen?
  _ << use_this_prefix
  _ << ' '
end
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/misc/show_configuration_options.rb, line 204
def opnn
  super(NAMESPACE)
end
prefix_to_use?() click to toggle source
#

prefix_to_use?

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 158
def prefix_to_use?
  dataset?.prefix?
end
reset() click to toggle source
#

reset

#
Calls superclass method Cookbooks::Base#reset
# File lib/cookbooks/misc/show_configuration_options.rb, line 65
def reset
  super()
  @data = nil
  @also_set_xorg_buffer = false
  @are_we_in_a_build_directory = false # true if we are in a BUILD/ directory.
end
return_appdir_prefix(i = '') click to toggle source
#

#return_appdir_prefix

We may have to use another version when we run from certain directories.

An example for this may be a directory called gobject-introspection-1.52.0 but the latest version in the cookbook files is 1.53.0.

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 308
def return_appdir_prefix(i = '')
  if i.include? '-'
    program_name, program_version = ProgramInformation.return_real_short_name_and_version(i)
  end
  _ = programs_directory?+
      program_name.capitalize+'/'+
      program_version
  return _
end
return_proper_configure_command() click to toggle source
#

#return_proper_configure_command

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 75
def return_proper_configure_command
  result = './'.dup
  result.prepend '.' if @are_we_in_a_build_directory
  result << @dataset.configure_command? # <- This usually adds the String 'configure'.
  result << ' ' unless result.end_with? ' '
  return result
end
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 360
def run
  determine_cookbook
  show_configuration_options
end
set_commandline_arguments(i) click to toggle source
#

#set_commandline_arguments

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 58
def set_commandline_arguments(i)
  @commandline_arguments = i
end
set_for_this_program(i = DEFAULT_PROGRAM_NAME) click to toggle source
#

#set_for_this_program

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 218
def set_for_this_program(i = DEFAULT_PROGRAM_NAME)
  if i.is_a? Array
    if i.size > 1 # This is the case for e. g.: "sco gcc XORG"
      case i[1]
      when 'XORG','BUFFER'
        @also_set_xorg_buffer = true
      end
    end
    i = i.first
  end
  if i.nil?
    # ===================================================================== #
    # In this case, use the current working directory.
    # ===================================================================== #
    _ = Dir.pwd
    if _.include?('-') && _.include?('.')
      i = ProgramInformation.return_name(File.basename(_)).delete('-').delete('_')
    else
      i = DEFAULT_PROGRAM_NAME
    end
  end
  i = i.to_s.dup
  i.downcase! # Since as of 20.09.2014.
  # ======================================================================= #
  # Keep in mind that the following check checks against the
  # downcased variant.
  # ======================================================================= #
  case i # case tag
  # ======================================================================= #
  # === appdir
  # ======================================================================= #
  when /-?-?appdir/,/-?-?appconf/,/^app/
    i = File.basename(Dir.pwd)
    # ===================================================================== #
    # Next, we can either .split('-') on that directory name, or we
    # use ProgramInformation instead.'
    # ===================================================================== #
    i = ProgramInformation.return_name(i).delete('-').delete('_')
    @dataset.prefix_to_use = return_appdir_prefix(File.basename(Dir.pwd))
  # ======================================================================= #
  # === sco --build
  # ======================================================================= #
  when /-?-?build/ # We may be in a directory called BUILD.
    if Dir.pwd.include? 'BUILD'
      i = File.basename(Dir.pwd.gsub(/BUILD$/,''))
      i = ProgramInformation.return_name(i)
      @are_we_in_a_build_directory = true
    end
  # ======================================================================= #
  # === --help
  # ======================================================================= #
  when /-?-?help/,'HELP'
    feedback_help_then_exit
  # ======================================================================= #
  # === --pwd
  # ======================================================================= #
  when /-?-?pwd/,'PWD'
    i = File.basename(Dir.pwd).split('-').first
  end
  # ======================================================================= #
  # Last but not least, we query whether there is an alias program name
  # but ONLY if the Cookbooks project does NOT include the given input.
  # ======================================================================= #
  if Cookbooks.is_included? i, :do_not_check_for_aliases
    result = i
  else # else pass it through our alias-filter there.
    result = find_cookbook_alias_for(i)
  end
  if result.nil? and # Try again in this case.
     ::Cookbooks.include_this_program?('lib'+i)
    result = 'lib'+i
  end
  if result
    unless result == i
      opnn; e 'Using the alias name `'+sfancy(result)+
              '` for the input `'+simp(i)+'` instead.'
      i = result
    end
  end
  @for_this_program = i
end
set_new_xorg_buffer(i = @data.join(' ')) click to toggle source
#

#set_new_xorg_buffer

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 86
def set_new_xorg_buffer(i = @data.join(' ')) 
  set_xorg_buffer(i) # Useful to set the xorg buffer.
end
show_configuration_options() click to toggle source
#

#show_configuration_options

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 93
def show_configuration_options
  # ======================================================================= #
  # Must check whether we have found the given input or whether we have not.
  # ======================================================================= #
  if found?
    condensed_configuration_options = ''.dup
    opnn; e "These are the configuration options for #{sfancy(@for_this_program)}"\
            " (we will also modify the xorg buffer):"+N+N
    @data = @dataset.configuration_options?.split(' ')
    # ===================================================================== #
    # Next, append the condensed configuration options.
    # ===================================================================== #
    @data.each {|entry|
      condensed_configuration_options << entry+' '
      entry.gsub!(/--/,'') # Get rid of '--' options.
      e '  --'+simp(entry)
    }
    e
    condensed_configuration_options.delete!(N)
    opnn; e 'Also showing the condensed format of these options next:'+N+N
    full_commandline = ''.dup
    full_commandline << return_proper_configure_command
    # ========================================================================= #
    # Append the prefix next. We will, however had, NOT insert the
    # prefix if the condensed_configuration_options already include '-prefix'
    # ========================================================================= #
    unless condensed_configuration_options.include? '-prefix'
      full_commandline << insert_prefix_to_use
    end
    full_commandline << condensed_configuration_options
    # ========================================================================= #
    # Next we output the full commandline. We will NOT show the name of
    # the class here though.
    # ========================================================================= #
    e '  '+simp(full_commandline)
    e
    set_new_xorg_buffer(full_commandline)
    store_last_configuration_options(full_commandline)
    opnn; e 'The above was assigned to the xorg-buffer as well, so you'
    opnn; e 'can very easily copy-paste this.'
  else
    opnn; e 'The given input `'+sfancy(input?)+'` was not found.'
    opnn; e 'This means that no program called that way could be '\
            'found to be registered.'
    opnn; e 'Another reason why it failed may be a typo, so make '\
            'sure to check the above input.'
  end
end
store_last_configuration_options(i) click to toggle source
#

#store_last_configuration_options

Use this method to store the last configure options used in a specific file, so that it can be read lateron.

Note that the target directory must exist, for this method to properly work.

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 151
def store_last_configuration_options(i)
  write_what_into(i, STORE_THE_LAST_CONFIGURATION_OPTIONS_IN_THIS_FILE)
end
this_program?() click to toggle source
#

this_program?

#
# File lib/cookbooks/misc/show_configuration_options.rb, line 186
def this_program?
  @for_this_program
end
Also aliased as: input?