Class: DRep::DRepCli

Inherits:
Object show all
Includes:
DRepRunnable
Defined in:
lib/drep/drep_cli.rb

Constant Summary collapse

DREP_EXEC_OPTIONS =
{:provider_flag =>
['-p', '--provider PROVIDER[;SOURCE_1[,SOURCE_2]][;RULE_1[,RULE_2]][;OPTIONS]',
 'Provider path with sources and rules specifications.'],
       :template_flag =>
['-t', '--template PATH[>OUTPUT_PATH]',
 'Template in/out path. By default output will be flushed to "STDOUT"'],
       :version_flag =>
['-v', '--version', 'Display version information and exit.'],
       :help_flag =>
['-h', '--help', 'Display this help message and exit.'],
       :quiet_flag =>
['-q', '--quiet', 'Start in quiet mode without any CLI messages.'],
       :verbose_flag =>
['-V', '--verbose', 'Start in verbose mode (ignored in quiet mode).'],
       :debug_flag =>
['-d', '--debug', 'Start in debug mode.']}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdin = STDIN, stdout = STDOUT, stderr = STDERR, arguments = []) ⇒ DRepCli

Returns a new instance of DRepCli.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/drep/drep_cli.rb', line 62

def initialize(stdin  = STDIN,
               stdout = STDOUT,
               stderr = STDERR, arguments = [])
  @options = OpenStruct.new()

  begin
    env_options = [stdin, stdout, stderr, @options]
    @env = DRepEnvironment.new(*env_options)
  rescue Exception => e
    unless @stderr.nil?
      @stderr.puts("#{UNIX_NAME}: initialization failed: #{e.message}")
    end
    exit(1)
  end

  @options.arguments = arguments.nil? ? [] : arguments
  
  @options.verbose = false
  @options.quiet   = false
  @options.debug   = false

  @options.output = @stdout

  @options.show_version = false
  @options.show_help    = false

  @options.providers = []
  @options.templates = []

  @parser = OptionParser.new()
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



56
57
58
# File 'lib/drep/drep_cli.rb', line 56

def env
  @env
end

#optionsObject (readonly)

Returns the value of attribute options.



58
59
60
# File 'lib/drep/drep_cli.rb', line 58

def options
  @options
end

#parserObject (readonly)

Returns the value of attribute parser.



60
61
62
# File 'lib/drep/drep_cli.rb', line 60

def parser
  @parser
end

Instance Method Details

#runObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/drep/drep_cli.rb', line 94

def run()
  if options_parsed?()
    begin
      if @options.verbose
        welcome_message = "#{FULL_NAME} has started"
        msg("#{welcome_message}: #{DateTime.now}.")
      end

      perform_tasks()

      if @options.verbose
        end_message = "#{FULL_NAME} has finished all tasks"
        msg("#{end_message}: #{DateTime.now}.")
      end
    rescue Exception => e
      err("Execution failed: #{e.message}")
    end
  end
end