Class: Slidict::Cli::Options::Flag

Inherits:
Struct
  • Object
show all
Defined in:
lib/slidict/cli/options.rb

Overview

One -x/--xxx declaration: how to parse it (arg placeholder, coercion) and how to describe it in --help output.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argObject

Returns the value of attribute arg

Returns:

  • (Object)

    the current value of arg



35
36
37
# File 'lib/slidict/cli/options.rb', line 35

def arg
  @arg
end

#coerceObject

Returns the value of attribute coerce

Returns:

  • (Object)

    the current value of coerce



35
36
37
# File 'lib/slidict/cli/options.rb', line 35

def coerce
  @coerce
end

#descObject

Returns the value of attribute desc

Returns:

  • (Object)

    the current value of desc



35
36
37
# File 'lib/slidict/cli/options.rb', line 35

def desc
  @desc
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



35
36
37
# File 'lib/slidict/cli/options.rb', line 35

def key
  @key
end

#switchesObject

Returns the value of attribute switches

Returns:

  • (Object)

    the current value of switches



35
36
37
# File 'lib/slidict/cli/options.rb', line 35

def switches
  @switches
end

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


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

def boolean?
  arg.nil?
end

#longObject



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

def long
  switches.find { |s| s.start_with?("--") }
end

#name_columnObject

Left column of the help listing, e.g. "-o, --output PATH" or, for a long-only flag, " --topic TEXT" -- the leading 4 spaces keep the "--name" text column-aligned either way.



51
52
53
54
# File 'lib/slidict/cli/options.rb', line 51

def name_column
  column = "#{short ? "#{short}, " : "    "}#{long}"
  arg ? "#{column} #{arg}" : column
end

#shortObject



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

def short
  switches.find { |s| !s.start_with?("--") }
end