Class: Lhj::Command::Config::Info

Inherits:
Lhj::Command::Config show all
Defined in:
lib/lhj/command/config/info.rb

Overview

show config info

Instance Method Summary collapse

Methods inherited from Lhj::Command

#auto_spin, #run, #stop

Constructor Details

#initialize(argv) ⇒ Info

Returns a new instance of Info.



11
12
13
14
# File 'lib/lhj/command/config/info.rb', line 11

def initialize(argv)
  @cli = HighLine.new
  super
end

Instance Method Details

#ask_which_oneObject



37
38
39
# File 'lib/lhj/command/config/info.rb', line 37

def ask_which_one
  @cli.ask('查看哪个配置: '.green).strip.to_i
end

#config_dirObject



41
42
43
# File 'lib/lhj/command/config/info.rb', line 41

def config_dir
  Lhj::Config.instance.home_dir
end

#handleObject



16
17
18
# File 'lib/lhj/command/config/info.rb', line 16

def handle
  show_config
end

#show_configObject



20
21
22
23
24
25
26
# File 'lib/lhj/command/config/info.rb', line 20

def show_config
  config_arr = Dir.glob("#{config_dir}/**/*.yml")
  config_arr.each_index { |i| puts "#{i}.#{File.basename(config_arr[i])}".yellow }
  idx = ask_which_one
  config_file = config_arr[idx]
  show_yaml(config_file)
end

#show_yaml(file) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/lhj/command/config/info.rb', line 28

def show_yaml(file)
  table_rows = []
  yaml = YAML.load_file(file)
  yaml.each { |key, value| table_rows << [key, value] }
  title = File.basename(file).to_s
  table = Terminal::Table.new title: title, headings: %w[ ], rows: table_rows
  puts table
end