Module: WifiWand::Commands::HelpSystem

Included in:
WifiWand::CommandLineInterface
Defined in:
lib/wifi_wand/commands/help_system.rb

Constant Summary collapse

HORIZONTAL_RULE =
'-' * 100
REPOSITORY_URL =
'https://github.com/keithrbennett/wifiwand'
LOCAL_README_PATH =
File.expand_path('../../../README.md', __dir__).freeze
HELP_BODY_WIDTH =
100
HELP_LEFT_COLUMN_WIDTH =
34
HELP_GAP =
'  '
HELP_LEADER =
'.'
HELP_DESCRIPTION_WIDTH =
HELP_BODY_WIDTH - HELP_LEFT_COLUMN_WIDTH - HELP_GAP.length
HELP_INDENT =
'  '
HELP_DESCRIPTION_INDENT =
HELP_INDENT + (' ' * HELP_LEFT_COLUMN_WIDTH) + HELP_GAP
HELP_SWITCHES =
[
  ['-h, --help', 'show this help message'],
  [
    '-o, --output-format FORMAT',
    'format for non-shell output: a=amazing_print, i=inspect, j=json, ' \
      'J=pretty_json, p=puts, P=pretty_print, y=yaml',
  ],
  [
    '-p, --wifi-interface interface_name',
    'specify WiFi interface name (overrides auto-detection)',
  ],
  ['-V, --version', 'show version'],
  [
    '-u, --utc BOOLEAN',
    'use UTC for timestamps (default: false, for local time); values: true/t/yes/y/+ or ' \
      'false/f/no/n/-; inline forms like --utc=true and -ufalse are accepted',
  ],
  [
    '-v, --verbose BOOLEAN',
    'verbose mode (prints OS commands and their outputs); values: true/t/yes/y/+ or false/f/no/n/-; ' \
      'inline forms like --verbose=true and -vfalse are accepted',
  ],
].freeze

Instance Method Summary collapse

Instance Method Details

#help_hintObject



86
# File 'lib/wifi_wand/commands/help_system.rb', line 86

def help_hint = "Use 'wifiwand help' or 'wifiwand -h' for help."

#help_textObject

Help text to be used when requested by 'h' command, in case of unrecognized or nonexistent command, etc.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wifi_wand/commands/help_system.rb', line 47

def help_text
  resource_help = resource_manager.open_resources.help_string
  commands = help_commands(resource_help)

  body = [
    HORIZONTAL_RULE,
    format_header_line('Usage', 'wifiwand [options] command [args]'),
    format_header_line('Repository', REPOSITORY_URL),
    format_header_line('Documentation (Local)', LOCAL_README_PATH),
    format_header_line('Version', WifiWand::VERSION),
    HORIZONTAL_RULE,
    nil,
    'WIFIWAND_OPTS can be used to set default options. ' \
      'Command-line arguments override these defaults.',
    'Example: export WIFIWAND_OPTS="--verbose true --output-format json"',
    nil,
    nil,
    section('Command Line Switches', HELP_SWITCHES),
    nil,
    nil,
    'Commands',
    '--------',
    nil,
    format_entries(commands),
    nil,
  ].map { |entry| entry.nil? ? '' : entry }.join("\n")

  "#{body}\n"
end


77
78
79
80
81
82
83
84
# File 'lib/wifi_wand/commands/help_system.rb', line 77

def print_help
  dest = if respond_to?(:interactive_mode) && interactive_mode
    $stdout
  else
    respond_to?(:out_stream) ? out_stream : $stdout
  end
  dest.puts help_text
end