From db6e06c1ef9985223e319eb8e904ccd542a07cd3 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Mon, 27 Sep 2021 16:07:08 +0200 Subject: [PATCH] Small fixes/changes/updates. * %-bars swaped from left to right. * fix qm: ct_cli -> qm. * ct conf aliased: pvecli ct cnf * conf set: no shortcut anymore (s and se) --- Gemfile.lock | 12 ++++++------ lib/pve/cli/base.rb | 14 +++++++------- lib/pve/cli/ct.rb | 4 ++-- lib/pve/cli/qm.rb | 2 +- lib/pve/helper.rb | 6 ++++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4ec80fd..41941e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - pve (0.1.1) + pve (0.1.3) activesupport (>= 2) dencli (~> 0.3.1) ipaddress (~> 0.8.3) @@ -11,26 +11,26 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (6.1.3.1) + activesupport (6.1.4.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - concurrent-ruby (1.1.8) + concurrent-ruby (1.1.9) dencli (0.3.1) diff-lcs (1.4.4) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) http-accept (1.7.0) - http-cookie (1.0.3) + http-cookie (1.0.4) domain_name (~> 0.5) i18n (1.8.10) concurrent-ruby (~> 1.0) ipaddress (0.8.3) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2021.0225) + mime-types-data (3.2021.0901) minitest (5.14.4) netrc (0.11.0) pmap (1.1.1) @@ -56,7 +56,7 @@ GEM concurrent-ruby (~> 1.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.7) + unf_ext (0.0.8) zeitwerk (2.4.2) PLATFORMS diff --git a/lib/pve/cli/base.rb b/lib/pve/cli/base.rb index 5ee17d8..eb77d62 100644 --- a/lib/pve/cli/base.rb +++ b/lib/pve/cli/base.rb @@ -86,13 +86,7 @@ def cli_base cli.sub :config, "CT/VM Configuration", min: 2, aliases: %w[cnf] do |ccli| ccli.cmd 'help', '', aliases: [nil, '-h', '--help'], &lambda {|*args| help ccli, *args } - ccli.cmd :show, "Show Config of CT/VM", &lambda {|name_or_id| - connect - th = Proxmox::LXC.find( name_or_id) || Proxmox::Qemu.find_by_name( name_or_id) - show_config th.config - } - - ccli.cmd :set, "Set Configs for CT/VM", &lambda {|name_or_id, *args| + ccli.cmd :set, "Set Configs for CT/VM", min: 3, &lambda {|name_or_id, *args| if %w[-h --help].include? name_or_id STDERR.puts "Usage: set -h|--help # Show help" STDERR.puts " set ct|vm --CNF1=VAL1 --CNF2=VAL2 ... # Set config-value. Empty value clears field." @@ -149,6 +143,12 @@ def cli_base th.cnfset opts show_config th.config, old } + + ccli.cmd :show, "Show Config of CT/VM", aliases: %w[s], &lambda {|name_or_id| + connect + th = Proxmox::LXC.find( name_or_id) || Proxmox::Qemu.find_by_name( name_or_id) + show_config th.config + } end cli.cmd :enter, "Enter Console of CT/Node", &lambda {|name_or_id| diff --git a/lib/pve/cli/ct.rb b/lib/pve/cli/ct.rb index 0d7fded..13be1a7 100644 --- a/lib/pve/cli/ct.rb +++ b/lib/pve/cli/ct.rb @@ -99,10 +99,10 @@ EOU create Proxmox::LXC, template, **ctopts }) - ct_cli.cmd( :config, 'Shows current config', &lambda {|name_or_id| + ct_cli.cmd( :config, 'Shows current config', aliases: %w[cnf], &lambda {|name_or_id| connect ct = Proxmox::LXC.find! name_or_id - STDOUT.puts ct.config.to_json + STDOUT.puts JSON.dump( ct.config) }) ct_cli.cmd( :resize, 'Resize a disk', &lambda {|name_or_id, disk, size| diff --git a/lib/pve/cli/qm.rb b/lib/pve/cli/qm.rb index 97bf4c1..4f36d7c 100644 --- a/lib/pve/cli/qm.rb +++ b/lib/pve/cli/qm.rb @@ -26,7 +26,7 @@ def cli_qm STDERR.puts "! #{$?.exitstatus}" unless Proxmox::Qemu.find!( name_or_id).exec *command } - ct_cli.cmd( :resize, 'Resize a disk', &lambda {|name_or_id, disk, size| + qm.cmd( :resize, 'Resize a disk', &lambda {|name_or_id, disk, size| connect qm = Proxmox::Qemu.find! name_or_id task = qm.resize disk, size diff --git a/lib/pve/helper.rb b/lib/pve/helper.rb index 54b5d34..1b662a5 100644 --- a/lib/pve/helper.rb +++ b/lib/pve/helper.rb @@ -112,10 +112,12 @@ class TablizedOutput def inspect() "#" end def to_s - y = w - (v*w).round + #y = w - (v*w).round + y = (v*w).round x = (100*v).round r = "%*s" % [w, 0==x ? 'ยท' : x] - "\e[0m#{r[0...y]}\e[1;4;#{0.75>v ? 32 : 31}m#{r[y..-1]}\e[0m" + #"\e[0m#{r[0...y]}\e[1;4;#{0.75>v ? 32 : 31}m#{r[y..-1]}\e[0m" + "\e[1;4;#{0.75>v ? 32 : 31}m#{r[0...y]}\e[0m#{r[y..-1]}" end end