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.



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

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



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

Returns a description of the supported command-line options.

Returns:

  • (String)

    a description of the supported command-line options



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

def help
  parse_opts(suppress_errors: true).to_s
end

#key?(key) ⇒ Boolean

Returns:

  • (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