Skip to content

Commit

Permalink
Use correct lizard command when custom executable is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrebenets committed Apr 6, 2018
1 parent d108a9d commit 5d1b76b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/fastlane/plugin/lizard/actions/lizard_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ def self.run(params)
UI.user_error!("The custom executable at '#{params[:executable]}' does not exist.")
end

lizard_cli_version = Gem::Version.new(`lizard --version`.scan(/(?:\d+\.?){3}/).first)
lizard_command = params[:executable].nil? ? "lizard" : "python #{params[:executable]}"

lizard_cli_version = Gem::Version.new(`#{lizard_command} --version 2>&1`.strip.scan(/(?:\d+\.?){3}/).first)
required_version = Gem::Version.new(Fastlane::Lizard::CLI_VERSION)
if lizard_cli_version < required_version
UI.user_error!("Your lizard version is outdated, please upgrade to at least version #{Fastlane::Lizard::CLI_VERSION} and start your lane again!")
end

command = forming_command(params)
command = forming_command(lizard_command, params)

if params[:show_warnings]
Fastlane::Actions.sh_control_output("lizard #{params[:source_folder]} | sed -n -e '/^$/,$p'", print_command: true, print_command_output: true)
Fastlane::Actions.sh_control_output("#{lizard_command} #{params[:source_folder]} | sed -n -e '/^$/,$p'", print_command: true, print_command_output: true)
end

begin
Expand All @@ -30,10 +32,9 @@ def self.run(params)
end
end

def self.forming_command(params)
def self.forming_command(lizard_command, params)
command = []
command << 'lizard' unless params[:executable]
command << "python #{params[:executable]}" if params[:executable]
command << lizard_command
command << params[:language].split(",").map { |l| "-l #{l.strip}" }.join(" ") if params[:language]
command << "--#{params[:export_type]}" if params[:export_type]
command << "-C #{params[:ccn]}" if params[:ccn] # stands for cyclomatic complexity number
Expand Down
9 changes: 9 additions & 0 deletions spec/fixtures/lizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Imitate "lizard.py --version" command by default.
import re, os, sys

version_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../lib/fastlane/plugin/lizard/version.rb')
pattern = '.*CLI_VERSION.*=.*"(?P<version>.*)"'
for line in open(version_file):
match = re.search(pattern, line)
if match:
sys.stdout.write(match.group('version'))

0 comments on commit 5d1b76b

Please sign in to comment.