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

Returns a new instance of Options.



31
32
33
34
# File 'lib/codeless_code/options.rb', line 31

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

Instance Method Details

#argsObject



40
41
42
# File 'lib/codeless_code/options.rb', line 40

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

#data_dirPathname

Returns Where on the file system to search for fables. Will default to DEFAULT_DATA if unspecified.

Returns:

  • (Pathname)

    Where on the file system to search for fables. Will default to DEFAULT_DATA if unspecified



50
51
52
# File 'lib/codeless_code/options.rb', line 50

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

#helpString

Returns a description of the supported command-line options.

Returns:

  • (String)

    a description of the supported command-line options



55
56
57
# File 'lib/codeless_code/options.rb', line 55

def help
  parse_opts(suppress_errors: true).to_s
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/codeless_code/options.rb', line 44

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

#optsObject



36
37
38
# File 'lib/codeless_code/options.rb', line 36

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