Class: Lhj::Command::Config::Info
- Inherits:
-
Lhj::Command::Config
- Object
- CLAide::Command
- Lhj::Command
- Lhj::Command::Config
- Lhj::Command::Config::Info
- Defined in:
- lib/lhj/command/config/info.rb
Overview
show config info
Instance Method Summary collapse
- #ask_which_one ⇒ Object
- #config_dir ⇒ Object
- #handle ⇒ Object
-
#initialize(argv) ⇒ Info
constructor
A new instance of Info.
- #show_config ⇒ Object
- #show_yaml(file) ⇒ Object
Methods inherited from Lhj::Command
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_one ⇒ Object
37 38 39 |
# File 'lib/lhj/command/config/info.rb', line 37 def ask_which_one @cli.ask('查看哪个配置: '.green).strip.to_i end |
#config_dir ⇒ Object
41 42 43 |
# File 'lib/lhj/command/config/info.rb', line 41 def config_dir Lhj::Config.instance.home_dir end |
#handle ⇒ Object
16 17 18 |
# File 'lib/lhj/command/config/info.rb', line 16 def handle show_config end |
#show_config ⇒ Object
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 |