Module: BranchIOCLI::Format::ShellFormat

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

Instance Method Summary collapse

Methods included from BranchIOCLI::Format

#render

Instance Method Details

#all_commandsObject



22
23
24
# File 'lib/branch_io_cli/format/shell_format.rb', line 22

def all_commands
  Dir[File.expand_path(File.join("..", "..", "command", "**_command.rb"), __FILE__)].map { |p| p.sub(%r{^.*/([a-z0-9_]+)_command.rb$}, '\1') }
end

#option(opt) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/branch_io_cli/format/shell_format.rb', line 6

def option(opt)
  o = @configuration.available_options.find { |o1| o1.name == opt.to_sym }

  cli_opt = opt.to_s.gsub(/_/, '-')

  all_opts = o.aliases || []

  if o.nil? || o.default_value.nil? || o.default_value != true
    all_opts << "--#{cli_opt}"
  else
    all_opts << "--no-#{cli_opt}"
  end

  all_opts.join(" ")
end

#options_for_command(command) ⇒ Object



26
27
28
29
# File 'lib/branch_io_cli/format/shell_format.rb', line 26

def options_for_command(command)
  @configuration = BranchIOCLI::Configuration.const_get("#{command.capitalize}Configuration")
  @configuration.available_options.map { |o| option(o.name) }.join(" ")
end