class Obfusc::CLI

This model receive and process ARGV from ./exe/obfusc script

Constants

VALID_COMMANDS

Attributes

argumetns[R]
options[R]

Public Class Methods

new(arguments) click to toggle source
# File lib/obfusc/cli.rb, line 10
def initialize(arguments)
  @arguments = arguments
  @options = {}
end

Public Instance Methods

run() click to toggle source
# File lib/obfusc/cli.rb, line 15
def run
  configure
  perform(@arguments.shift)
end

Protected Instance Methods

configure() click to toggle source
# File lib/obfusc/cli.rb, line 32
def configure
  parser.parse!(@arguments)
end
parser() click to toggle source

rubocop:disable BlockLength,MethodLength,AbcSize

# File lib/obfusc/cli.rb, line 37
def parser
  @parser = OptionParser.new do |opts|
    opts.banner = 'Usage: obfusc <command> <arguments> <options>'
    opts.separator ''
    opts.separator 'Commands:'
    VALID_COMMANDS.each do |command|
      opts.separator "    * #{command}"
    end

    opts.separator ''
    opts.separator 'Specific options:'

    opts.on('-c', '--config FILENAME',
            'Using a different ".obfusc.cnf" filename') do |filename|
      @options[:config_path] = filename
    end

    opts.on(
      '-e',
      '--extension STRING',
      'Specify a custom file extension. (Default to "obfc")'
    ) do |extension|
      @options[:extension] = extension
    end

    opts.on(
      '-p',
      '--prefix STRING',
      'Specify a custom file prefix. (Default to "obfc")'
    ) do |prefix|
      @options[:prefix] = prefix
    end

    opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
      @options[:verbose] = v
    end

    opts.on(
      '-s',
      '--[no-]simulate',
      'Do a simulate run without executing actions'
    ) do |v|
      @options[:simulate] = v
    end

    opts.separator ''
    opts.separator 'Common options:'

    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit
    end
  end
end
perform(command) click to toggle source
# File lib/obfusc/cli.rb, line 22
def perform(command)
  unless VALID_COMMANDS.include?(command)
    puts parser.help
    return
  end
  config = Obfusc::Config.new(@options)
  class_name = "#{command[0].upcase}#{command[1..-1]}Command"
  Obfusc.const_get(class_name).call(config, *@arguments)
end