Class: SshyGuy::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sshyguy/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.



32
33
34
# File 'lib/sshyguy/cli.rb', line 32

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/sshyguy/cli.rb', line 31

def options
  @options
end

Class Method Details

.runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sshyguy/cli.rb', line 11

def self.run
  options = {}
  OptionParser.new do |opts|
    opts.banner = 'Usage: sshyguy [options]'
    opts.on('-h', '--help', 'Help') do |_v|
      options[:help] = true
    end
    opts.on('-s', '--shortcut SHORTCUT', 'Shortcut') do |v|
      options[:shortcut] = v
    end
    opts.on('--install') do |_v|
      options[:install] = true
    end
    opts.on('-d', '--debug', 'Debug') do |_v|
      SshyGuy.config.debug = true
    end
  end.parse!
  new(options).run
end

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sshyguy/cli.rb', line 36

def run
  if options[:install]
    puts "Writing to #{SshyGuy.config_file}"
    File.open(SshyGuy.config_file, 'w+') { |f| f.puts(File.read('lib/data/example.json')) }
    exit
  end
  SshyGuy.log('Loading config')
  SshyGuy.load_config!
  if options[:help]
    Screens::HelpScreen.show(options)
  else
    Screens::MainScreen.show(options)
  end
end