Class: CI::Syntax::Tool::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/ci-syntax-tool/command_line.rb

Overview

CI::Syntax::Tool::CommandLine

a class to parse and represent the CLI options
also handles degenerate CLI cases, like --help,
--version, --list-languages, --list-formatters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CommandLine

Returns a new instance of CommandLine.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ci-syntax-tool/command_line.rb', line 18

def initialize(args)
  @args = args.dup
  @runnable = true
  @non_runnable_exit_status = 0
  @options = {
    languages: [],
    requires: [],
    formats: [],
    outputs: [],
  }
  @file_args = []
  
  @parser = make_parser

  parse_args
  validate_file_args if runnable?
  load_requires if runnable?
  validate_languages if runnable?
  validate_formats if runnable?
  list_languages if runnable? && @options[:list_languages]
  list_formats if runnable? && @options[:list_formats]

end

Instance Attribute Details

#file_argsObject (readonly)

Returns the value of attribute file_args.



16
17
18
# File 'lib/ci-syntax-tool/command_line.rb', line 16

def file_args
  @file_args
end

#formattersObject (readonly)

Returns the value of attribute formatters.



14
15
16
# File 'lib/ci-syntax-tool/command_line.rb', line 14

def formatters
  @formatters
end

#languagesObject (readonly)

Returns the value of attribute languages.



13
14
15
# File 'lib/ci-syntax-tool/command_line.rb', line 13

def languages
  @languages
end

#non_runnable_exit_statusObject

Returns the value of attribute non_runnable_exit_status.



12
13
14
# File 'lib/ci-syntax-tool/command_line.rb', line 12

def non_runnable_exit_status
  @non_runnable_exit_status
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/ci-syntax-tool/command_line.rb', line 15

def options
  @options
end

Instance Method Details

#runnable?Boolean

rubocop: disable Style/TrivialAccessors

Returns:

  • (Boolean)


43
44
45
# File 'lib/ci-syntax-tool/command_line.rb', line 43

def runnable?
  @runnable
end