Module: BranchIOCLI::Format::MarkdownFormat

Includes:
BranchIOCLI::Format
Defined in:
lib/branch_io_cli/format/markdown_format.rb

Instance Method Summary collapse

Methods included from BranchIOCLI::Format

#option, #render

Instance Method Details

#header(text, level = 1) ⇒ Object



6
7
8
# File 'lib/branch_io_cli/format/markdown_format.rb', line 6

def header(text, level = 1)
  "#" * level + " #{text}"
end

#highlight(text) ⇒ Object



10
11
12
# File 'lib/branch_io_cli/format/markdown_format.rb', line 10

def highlight(text)
  "`#{text}`"
end

#italics(text) ⇒ Object



14
15
16
# File 'lib/branch_io_cli/format/markdown_format.rb', line 14

def italics(text)
  "_#{text}_"
end

#render_command(name) ⇒ Object



56
57
58
59
# File 'lib/branch_io_cli/format/markdown_format.rb', line 56

def render_command(name)
  @command = BranchIOCLI::Command.const_get("#{name.to_s.capitalize}Command")
  render :command
end

#table_option(option) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/branch_io_cli/format/markdown_format.rb', line 22

def table_option(option)
  text = "|#{option.aliases.join(', ')}"
  text += ", " unless option.aliases.blank?

  text += "--"
  text += "[no-]" if option.negatable
  text += option.name.to_s.gsub(/_/, '-')

  if option.example
    text += " "
    text += "[" if option.argument_optional
    text += option.example
    text += "]" if option.argument_optional
  end

  text += "|#{option.description}"

  if option.type.nil?
    default_value = option.default_value ? "yes" : "no"
  else
    default_value = option.default_value
  end

  if default_value
    text += " (default: #{default_value})"
  end

  text += "|"
  text += option.env_name if option.env_name

  text += "|"
  text
end

#table_optionsObject



18
19
20
# File 'lib/branch_io_cli/format/markdown_format.rb', line 18

def table_options
  @command.available_options.map { |o| table_option o }.join("\n")
end