Class: CodelessCode::Options

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/codeless_code/options.rb

Overview

Adapter class for ARGV which exposes the command-line arguments as data types.

Constant Summary collapse

MAX_ARGS =

–number flag may be passed as argument cmd 3 vs cmd -N 3

1

Instance Method Summary collapse

Constructor Details

#initialize(command_name, argv) ⇒ Options


33
34
35
36
# File 'lib/codeless_code/options.rb', line 33

def initialize(command_name, argv)
  @command_name = command_name
  @argv = argv
end

Instance Method Details

#argsObject


42
43
44
# File 'lib/codeless_code/options.rb', line 42

def args
  opts.arguments[1..-1]
end

#data_dirPathname


52
53
54
# File 'lib/codeless_code/options.rb', line 52

def data_dir
  @data_dir ||= self[:path] ? Pathname.new(self[:path]) : DEFAULT_DATA
end

#helpString


57
58
59
# File 'lib/codeless_code/options.rb', line 57

def help
  parse_opts(suppress_errors: true).to_s
end

#key?(key) ⇒ Boolean


46
47
48
# File 'lib/codeless_code/options.rb', line 46

def key?(key)
  !!self[key]
end

#optsObject


38
39
40
# File 'lib/codeless_code/options.rb', line 38

def opts
  @opts ||= parse_opts(suppress_errors: false)
end