lib/rtprov/cli.rb in rtprov-0.1.2 vs lib/rtprov/cli.rb in rtprov-0.1.3

- old
+ new

@@ -17,21 +17,21 @@ def show(router_name) puts Router.decrypt(router_name) end desc "get ROUTER", "Get config from router" - option :number, type: :numeric, default: 0, aliases: :n, desc: "Configuration number" + option :filename, type: :string, default: "/system/config", aliases: :f, desc: "Configuration file" def get(router_name) router = Router.load(router_name) sftp = Sftp.new(router.host, router.user, router.administrator_password) - puts sftp.get("/system/config#{options[:number]}") + puts sftp.get(options[:filename]) end desc "diff ROUTER TEMPLATE", "Show config diff of current and new config" - option :number, type: :numeric, default: 0, aliases: :n, desc: "Configuration number" + option :filename, type: :string, default: "/system/config", aliases: :f, desc: "Configuration file" def diff(router_name, template_name) - current_file = "/system/config#{options[:number]}" + current_file = options[:filename] router = Router.load(router_name) template = Template.find(router_name, template_name) new_config = template.render(router.variables) @@ -39,12 +39,12 @@ current_config = sftp.get(current_file) diff = ENV["RTPROV_DIFF"] || %w(colordiff diff).find {|cmd| system("which", cmd, out: "/dev/null", err: "/dev/null") } Dir.mktmpdir do |dir| Dir.chdir(dir) do - File.write("new.conf", new_config.gsub(/^#.*$/, "").gsub(/(\r\n|\r|\n)+/, "\r\n")) - File.write("current.conf", current_config.gsub(/^#.*$/, "").gsub(/(\r\n|\r|\n)+/, "\r\n")) + File.write("new.conf", new_config.gsub(/^\s*#.*$/, "").gsub(/(\r\n|\r|\n)+/, "\r\n").chomp) + File.write("current.conf", current_config.gsub(/^\s*#.*$/, "").gsub(/\s+$/, "").gsub(/(\r\n|\r|\n)+/, "\r\n").chomp) system("#{diff} -u current.conf new.conf", out: $stdout, err: $stderr) end end end @@ -87,10 +87,9 @@ end end end desc "print ROUTER TEMPLATE", "Print config" - option :number, type: :numeric, default: 0, aliases: :n, desc: "Configuration number" def print(router_name, template_name) router = Router.load(router_name) template = Template.find(router_name, template_name) new_config = template.render(router.variables)