Module: ChefApply::CLI::Help

Included in:
ChefApply::CLI
Defined in:
lib/chef_apply/cli/help.rb

Constant Summary collapse

T =
ChefApply::Text.cli

Instance Method Summary collapse

Instance Method Details

#format_flagsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef_apply/cli/help.rb', line 32

def format_flags
  flag_text = "FLAGS:\n"
  justify_length = 0
  options.each_value do |spec|
    justify_length = [justify_length, spec[:long].length + 4].max
  end
  options.sort.to_h.each_value do |flag_spec|
    short = flag_spec[:short] || "  "
    short = short[0, 2] # We only want the flag portion, not the capture portion (if present)
    if short == "  "
      short = "    "
    else
      short = "#{short}, "
    end
    flags = "#{short}#{flag_spec[:long]}"
    flag_text << "    #{flags.ljust(justify_length)}    "
    ml_padding = " " * (justify_length + 8)
    first = true
    flag_spec[:description].split("\n").each do |d|
      flag_text << ml_padding unless first
      first = false
      flag_text << "#{d}\n"
    end
  end
  flag_text
end

#format_helpObject



26
27
28
29
30
# File 'lib/chef_apply/cli/help.rb', line 26

def format_help
  help_text = banner.clone # This prevents us appending to the banner text
  help_text << "\n"
  help_text << format_flags
end

#show_helpObject



22
23
24
# File 'lib/chef_apply/cli/help.rb', line 22

def show_help
  UI::Terminal.output format_help
end

#show_versionObject



63
64
65
66
# File 'lib/chef_apply/cli/help.rb', line 63

def show_version
  require_relative "../version"
  UI::Terminal.output T.version.show(ChefApply::VERSION)
end

#usageObject



59
60
61
# File 'lib/chef_apply/cli/help.rb', line 59

def usage
  T.usage
end