From d4ee04322ce642c602269738e45f63b800d78cf7 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 21 Jun 2016 15:59:27 -0700 Subject: fix ruby deprecation warnings --- lib/leap_cli/leapfile.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'lib/leap_cli/leapfile.rb') diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb index 9164d0a..ac40237 100644 --- a/lib/leap_cli/leapfile.rb +++ b/lib/leap_cli/leapfile.rb @@ -62,7 +62,7 @@ module LeapCli # load the platform # platform_file = "#{@platform_directory_path}/platform.rb" - unless File.exists?(platform_file) + unless File.exist?(platform_file) Util.bail! "ERROR: The file `#{platform_file}` does not exist. Please check the value of `@platform_directory_path` in `Leapfile` or `~/.leaprc`." end require "#{@platform_directory_path}/platform.rb" @@ -73,12 +73,6 @@ module LeapCli "You need either leap command #{Leap::Platform.compatible_cli.first} to #{Leap::Platform.compatible_cli.last} or " + "platform version #{LeapCli::COMPATIBLE_PLATFORM_VERSION.first} to #{LeapCli::COMPATIBLE_PLATFORM_VERSION.last}" end - unless @allow_production_deploy.nil? - Util::log 0, :warning, "in Leapfile: @allow_production_deploy is no longer supported." - end - unless @platform_branch.nil? - Util::log 0, :warning, "in Leapfile: @platform_branch is no longer supported." - end @valid = true return @valid end @@ -105,7 +99,7 @@ module LeapCli def edit_leaprc(property, value=nil) file_path = leaprc_path lines = [] - if File.exists?(file_path) + if File.exist?(file_path) regexp = /self\.#{Regexp.escape(property)} = .*? if @provider_directory_path == '#{Regexp.escape(@provider_directory_path)}'/ File.readlines(file_path).each do |line| unless line =~ regexp @@ -128,7 +122,7 @@ module LeapCli end def read_settings(file) - if File.exists? file + if File.exist? file Util::log 2, :read, file instance_eval(File.read(file), file) validate(file) -- cgit v1.2.3 From 64704deccddd9db46ea9ec4992207b8b2d51f1f8 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 29 Jun 2016 16:52:31 -0700 Subject: move everything we can to leap_platform/lib/leap_cli --- lib/leap_cli/leapfile.rb | 64 +++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'lib/leap_cli/leapfile.rb') diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb index ac40237..10af224 100644 --- a/lib/leap_cli/leapfile.rb +++ b/lib/leap_cli/leapfile.rb @@ -3,6 +3,8 @@ # # It is akin to a Gemfile, Rakefile, or Capfile (e.g. it is a ruby file that gets eval'ed) # +# Additional configuration options are defined in platform's leapfile_extensions.rb +# module LeapCli def self.leapfile @@ -10,17 +12,11 @@ module LeapCli end class Leapfile - attr_accessor :platform_directory_path - attr_accessor :provider_directory_path - attr_accessor :custom_vagrant_vm_line - attr_accessor :leap_version - attr_accessor :log - attr_accessor :vagrant_network - attr_accessor :vagrant_basebox - attr_accessor :environment + attr_reader :platform_directory_path + attr_reader :provider_directory_path + attr_reader :environment def initialize - @vagrant_network = '10.5.5.0/24' end # @@ -61,19 +57,33 @@ module LeapCli # # load the platform # - platform_file = "#{@platform_directory_path}/platform.rb" - unless File.exist?(platform_file) + platform_class = "#{@platform_directory_path}/lib/leap/platform" + platform_definition = "#{@platform_directory_path}/platform.rb" + unless File.exist?(platform_definition) Util.bail! "ERROR: The file `#{platform_file}` does not exist. Please check the value of `@platform_directory_path` in `Leapfile` or `~/.leaprc`." end - require "#{@platform_directory_path}/platform.rb" - if !Leap::Platform.compatible_with_cli?(LeapCli::VERSION) || - !Leap::Platform.version_in_range?(LeapCli::COMPATIBLE_PLATFORM_VERSION) - Util.bail! "This leap command (v#{LeapCli::VERSION}) " + - "is not compatible with the platform #{@platform_directory_path} (v#{Leap::Platform.version}).\n " + - "You need either leap command #{Leap::Platform.compatible_cli.first} to #{Leap::Platform.compatible_cli.last} or " + - "platform version #{LeapCli::COMPATIBLE_PLATFORM_VERSION.first} to #{LeapCli::COMPATIBLE_PLATFORM_VERSION.last}" + require platform_class + require platform_definition + begin + Leap::Platform.validate!(LeapCli::VERSION, LeapCli::COMPATIBLE_PLATFORM_VERSION, self) + rescue StandardError => exc + Util.bail! exc.to_s + end + leapfile_extensions = "#{@platform_directory_path}/lib/leap_cli/leapfile_extensions.rb" + if File.exist?(leapfile_extensions) + require leapfile_extensions + end + + # + # validate + # + instance_variables.each do |var| + var = var.to_s.sub('@', '') + if !self.respond_to?(var) + LeapCli.log :warning, "the variable `#{var}` is set in .leaprc or Leapfile, but it is not supported." + end end - @valid = true + @valid = validate return @valid end end @@ -123,9 +133,8 @@ module LeapCli def read_settings(file) if File.exist? file - Util::log 2, :read, file + LeapCli.log 2, :read, file instance_eval(File.read(file), file) - validate(file) end end @@ -140,11 +149,16 @@ module LeapCli return search_dir end - PRIVATE_IP_RANGES = /(^127\.0\.0\.1)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/ + # to be overridden + def validate + return true + end - def validate(file) - Util::assert! vagrant_network =~ PRIVATE_IP_RANGES do - Util::log 0, :error, "in #{file}: vagrant_network is not a local private network" + def method_missing(method, *args) + if method =~ /=$/ + self.instance_variable_set('@' + method.to_s.sub('=',''), args.first) + else + self.instance_variable_get('@' + method.to_s) end end -- cgit v1.2.3 From d1a12ae7aa2660f10046bc7baad688819c61168c Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 4 Jul 2016 10:24:47 -0700 Subject: fix tests --- lib/leap_cli/leapfile.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/leap_cli/leapfile.rb') diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb index 10af224..3dadf66 100644 --- a/lib/leap_cli/leapfile.rb +++ b/lib/leap_cli/leapfile.rb @@ -15,6 +15,7 @@ module LeapCli attr_reader :platform_directory_path attr_reader :provider_directory_path attr_reader :environment + attr_reader :valid def initialize end -- cgit v1.2.3 From a8efdb865dbea99e619c0353d707da39118e6e28 Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 9 Jul 2016 02:45:23 -0700 Subject: test: added test of quick start tutorial commands --- lib/leap_cli/leapfile.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib/leap_cli/leapfile.rb') diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb index 3dadf66..0b56b71 100644 --- a/lib/leap_cli/leapfile.rb +++ b/lib/leap_cli/leapfile.rb @@ -150,11 +150,6 @@ module LeapCli return search_dir end - # to be overridden - def validate - return true - end - def method_missing(method, *args) if method =~ /=$/ self.instance_variable_set('@' + method.to_s.sub('=',''), args.first) -- cgit v1.2.3 From 5e266e1f9d22fbb78612a896f47a19be5106aee1 Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 1 Sep 2016 13:22:33 -0700 Subject: print friendly message if leap_platform is too old (closes #8423) --- lib/leap_cli/leapfile.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/leap_cli/leapfile.rb') diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb index 0b56b71..e526703 100644 --- a/lib/leap_cli/leapfile.rb +++ b/lib/leap_cli/leapfile.rb @@ -63,8 +63,19 @@ module LeapCli unless File.exist?(platform_definition) Util.bail! "ERROR: The file `#{platform_file}` does not exist. Please check the value of `@platform_directory_path` in `Leapfile` or `~/.leaprc`." end - require platform_class - require platform_definition + begin + require platform_class + require platform_definition + rescue LoadError + Util.log "The leap_platform at #{platform_directory_path} is not compatible with this version of leap_cli" + Util.log "You can either:" do + Util.log "Upgrade leap_platform to version " + LeapCli::COMPATIBLE_PLATFORM_VERSION.first + Util.log "Or, downgrade leap_cli to version 1.8" + end + Util.bail! + rescue StandardError => exc + Util.bail! exc.to_s + end begin Leap::Platform.validate!(LeapCli::VERSION, LeapCli::COMPATIBLE_PLATFORM_VERSION, self) rescue StandardError => exc -- cgit v1.2.3