From 5cdaabb56f2b34722464e8cf739c7bdc6c7ce4dd Mon Sep 17 00:00:00 2001 From: Alexande B Date: Thu, 15 Jul 2021 16:43:44 +0200 Subject: [PATCH 1/2] metanorma/metanorma#202 add socksify dependency and support SOCKS_PROXY env var --- exe/metanorma | 16 +++++++++++++++- metanorma-cli.gemspec | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/exe/metanorma b/exe/metanorma index a25361ad..33468daa 100755 --- a/exe/metanorma +++ b/exe/metanorma @@ -17,4 +17,18 @@ end # start up the CLI require "metanorma/cli" -Metanorma::Cli.start(ARGV) +metanorma_cli = proc { Metanorma::Cli.start(ARGV) } +if ENV["SOCKS_PROXY"] + require "socksify" + require "uri" + begin + proxy = URI.parse(ENV["SOCKS_PROXY"]) + Socksify::proxy(proxy.host, proxy.port, &metanorma_cli) + rescue URI::InvalidURIError + warn "Value of ENV.SOCKS_PROXY=#{ENV['SOCKS_PROXY']} is invalid! Droping it" + ENV.delete("SOCKS_PROXY") + metanorma_cli.call + end +else + metanorma_cli.call +end diff --git a/metanorma-cli.gemspec b/metanorma-cli.gemspec index 7b53ae41..2f045607 100644 --- a/metanorma-cli.gemspec +++ b/metanorma-cli.gemspec @@ -58,4 +58,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "metanorma-ogc", "~> 1.3.0" spec.add_runtime_dependency "metanorma-un", "~> 0.6.0" spec.add_runtime_dependency "relaton-cli", ">= 0.8.2" + + spec.add_runtime_dependency "socksify" end From 037c87c446de7871037bc7a4dadf3acbe9b4d874 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Thu, 15 Jul 2021 17:00:41 +0200 Subject: [PATCH 2/2] Fix rubocop issues in metanorma, git_template.rb --- exe/metanorma | 6 ++++-- lib/metanorma/cli/git_template.rb | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/exe/metanorma b/exe/metanorma index 33468daa..24b11b86 100755 --- a/exe/metanorma +++ b/exe/metanorma @@ -11,8 +11,10 @@ $:.unshift File.expand_path("../../lib", bin_file) # Fixes https://github.com/rubygems/rubygems/issues/1420 require "rubygems/specification" -class Gem::Specification - def this; self; end +module Gem + class Specification + def this; self; end + end end # start up the CLI diff --git a/lib/metanorma/cli/git_template.rb b/lib/metanorma/cli/git_template.rb index 7282fe21..da84e91a 100644 --- a/lib/metanorma/cli/git_template.rb +++ b/lib/metanorma/cli/git_template.rb @@ -10,16 +10,15 @@ def initialize(name, options = {}) def remove! remove_template - return true + true end def download remove! clone_git_template(options[:repo]) - rescue Git::GitExecuteError UI.say("Invalid template reoository!") - return nil + nil end def find_or_download @@ -86,7 +85,7 @@ def git_repos iso: "https://github.com/metanorma/mn-templates-iso", iec: "https://github.com/metanorma/mn-templates-iec", itu: "https://github.com/metanorma/mn-templates-itu", - ietf: "https://github.com/metanorma/mn-templates-ietf" + ietf: "https://github.com/metanorma/mn-templates-ietf", } end