Class: Avmtrf1::Tools::Runner::Red

Inherits:
EacRubyUtils::Console::DocoptRunner
  • Object
show all
Includes:
EacRubyUtils::Console::Speaker, EacRubyUtils::SimpleCache
Defined in:
lib/avmtrf1/tools/runner/red.rb

Constant Summary collapse

DOC =
<<~DOCOPT
  Utilidades para RED.

  Usage:
    __PROGRAM__ [options] [-i <red-ini-path>] file put <file>
    __PROGRAM__ -h | --help

  Options:
    -h --help                      Mostra esta ajuda.
    -i --red-ini=<red-ini-path>    Arquivo red.ini com parâmetros de conexão e upload.
    -p --red-profile=<red-profile>       Perfil/seção do red.ini [default: development].
DOCOPT

Instance Method Summary collapse

Instance Method Details

#fileObject



60
61
62
# File 'lib/avmtrf1/tools/runner/red.rb', line 60

def file
  required_file('<file>')
end

#file_putObject



44
45
46
47
48
49
50
# File 'lib/avmtrf1/tools/runner/red.rb', line 44

def file_put
  result = red_profile.put_file(file)
  require 'pp'
  puts '>' * 20
  puts result
  puts '<' * 20
end

#red_ini_path_uncachedObject



64
65
66
# File 'lib/avmtrf1/tools/runner/red.rb', line 64

def red_ini_path_uncached
  required_file('--red-ini')
end

#red_ini_profileObject



72
73
74
75
76
# File 'lib/avmtrf1/tools/runner/red.rb', line 72

def red_ini_profile
  return  red_ini.profiles[red_profile_name] if red_ini.profiles.key?(red_profile_name)

  fatal_error "Perfil/seção \"#{red_profile_name}\" não encontrada em \"#{red_ini_path}\""
end

#red_ini_uncachedObject



68
69
70
# File 'lib/avmtrf1/tools/runner/red.rb', line 68

def red_ini_uncached
  ::Avmtrf1::Ini.new(red_ini_path)
end

#red_profile_nameObject



52
53
54
# File 'lib/avmtrf1/tools/runner/red.rb', line 52

def red_profile_name
  options.fetch('--red-profile')
end

#red_profile_uncachedObject



56
57
58
# File 'lib/avmtrf1/tools/runner/red.rb', line 56

def red_profile_uncached
  ::Avmtrf1::Red::Profile.by_ini_profile(red_ini_profile)
end

#required_file(option_key) ⇒ Object



78
79
80
81
82
83
# File 'lib/avmtrf1/tools/runner/red.rb', line 78

def required_file(option_key)
  path = options.fetch(option_key)
  return path if path

  fatal_error("Arquivo \"#{path}\" não existe (Informado na opção #{option_key})")
end

#runObject



29
30
31
32
33
34
35
36
# File 'lib/avmtrf1/tools/runner/red.rb', line 29

def run
  start_banner
  if options.fetch('file') && options.fetch('put')
    file_put
  else
    fatal_error('Subcomando não mapeado (Isto é um defeito do software)')
  end
end

#start_bannerObject



38
39
40
41
42
# File 'lib/avmtrf1/tools/runner/red.rb', line 38

def start_banner
  infov 'red.ini', options.fetch('--red-ini')
  infov 'Perfil de red.ini', red_profile_name
  infov 'Arquivo para upload', options.fetch('<file>')
end