-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to separate Cli::Command::Environment abstraction
* This allows to add other subcommands that depend on the environment without adding duplication
- Loading branch information
Showing
5 changed files
with
63 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ def full_name | |
# | ||
# @return [Bool] | ||
def zombie? | ||
instance_of?(Run) | ||
false | ||
end | ||
|
||
private | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutant | ||
module CLI | ||
class Command | ||
class Environment | ||
class Run < self | ||
NAME = 'run' | ||
SHORT_DESCRIPTION = 'Run code analysis' | ||
|
||
SLEEP = 40 | ||
|
||
UNLICENSED = <<~MESSAGE.lines.freeze | ||
Soft fail, continuing in #{SLEEP} seconds | ||
Next major version will enforce the license | ||
See https://github.com/mbj/mutant#licensing | ||
MESSAGE | ||
|
||
# Test if command needs to be executed in zombie environment | ||
# | ||
# @return [Bool] | ||
def zombie? | ||
@config.zombie | ||
end | ||
|
||
private | ||
|
||
def execute | ||
soft_fail(License.apply(world)) | ||
.bind { Config.load_config_file(world) } | ||
.fmap(&method(:expand)) | ||
.bind { Bootstrap.apply(world, @config) } | ||
.bind(&Runner.public_method(:apply)) | ||
.from_right { |error| world.stderr.puts(error); return false } | ||
.success? | ||
end | ||
|
||
def soft_fail(result) | ||
result.either( | ||
lambda do |message| | ||
stderr = world.stderr | ||
stderr.puts(message) | ||
UNLICENSED.each { |line| stderr.puts(unlicensed(line)) } | ||
world.kernel.sleep(SLEEP) | ||
Either::Right.new(nil) | ||
end, | ||
->(_subscription) { Either::Right.new(nil) } | ||
) | ||
end | ||
|
||
def unlicensed(message) | ||
"[Mutant-License-Error]: #{message}" | ||
end | ||
end # Run | ||
end # Environment | ||
end # Command | ||
end # CLI | ||
end # Mutant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters