Module: PatchELF::CLI

Extended by:
CLI
Included in:
CLI
Defined in:
lib/patchelf/cli.rb

Overview

For command line interface to parsing arguments.

Constant Summary collapse

SCRIPT_NAME =

Name of binary.

'patchelf.rb'.freeze
USAGE =

CLI usage string.

format('Usage: %s <commands> FILENAME [OUTPUT_FILE]', SCRIPT_NAME).freeze

Class Method Summary collapse

Class Method Details

.work(argv) ⇒ void

This method returns an undefined value.

Main method of CLI.

Examples:

PatchELF::CLI.work(%w[--help])
# usage message to stdout
PatchELF::CLI.work(%w[--version])
# version message to stdout

Parameters:

  • argv (Array<String>)

    Command line arguments.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/patchelf/cli.rb', line 27

def work(argv)
  @options = {
    set: {},
    print: [],
    needed: []
  }
  return $stdout.puts "PatchELF Version #{PatchELF::VERSION}" if argv.include?('--version')
  return $stdout.puts option_parser unless parse(argv)

  # Now the options are (hopefully) valid, let's process the ELF file.
  begin
    @patcher = PatchELF::Patcher.new(@options[:in_file])
  rescue ELFTools::ELFError, Errno::ENOENT => e
    return PatchELF::Logger.error(e.message)
  end
  patcher.use_rpath! if @options[:force_rpath]
  readonly
  patch_requests
  patcher.save(@options[:out_file])
end