Skip to content

Commit

Permalink
Merge pull request #2 from devmasx/refactor-params
Browse files Browse the repository at this point in the history
Refactor params
  • Loading branch information
MiguelSavignano committed Feb 14, 2020
2 parents 5f1a842 + a10bc2a commit 45c169f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
23 changes: 10 additions & 13 deletions spec/cached_docker/app_spec.cr
Expand Up @@ -3,9 +3,8 @@ require "../spec_helper"
describe CachedDocker::App do
it "#commands" do
subject = CachedDocker::App.new(
"crystal-dev",
"v1",
"",
image_name: "crystal-dev",
image_tag: "v1",
)
subject.commands.should eq([
"docker pull crystal-dev",
Expand All @@ -20,11 +19,10 @@ describe CachedDocker::App do

it "#initialize set default values" do
subject = CachedDocker::App.new(
"crystal-dev",
"",
"--build-arg=NPM_TOKEN=1234",
"",
"Dockerfile"
image_name: "crystal-dev",
image_tag: "",
build_params: "--build-arg=NPM_TOKEN=1234",
dockerfile_path: "Dockerfile"
)
subject.image_tag.should eq(Time.utc.to_unix.to_s)
subject.dockerfile_path.should eq("Dockerfile")
Expand All @@ -33,11 +31,10 @@ describe CachedDocker::App do

it "#commands" do
subject = CachedDocker::App.new(
"crystal-dev",
"v1",
"--build-arg=NPM_TOKEN=1234",
"",
"Dockerfile"
image_name: "crystal-dev",
image_tag: "v1",
build_params: "--build-arg=NPM_TOKEN=1234",
dockerfile_path: "Dockerfile"
)

subject.commands.should eq([
Expand Down
14 changes: 7 additions & 7 deletions src/cached_docker.cr
Expand Up @@ -47,7 +47,7 @@ cli = Commander::Command.new do |cmd|
flag.name = "dockerfile_path"
flag.long = "--file"
flag.short = "-f"
flag.default = ""
flag.default = "./Dockerfile"
flag.description = "Name of the Dockerfile (Default is 'PATH/Dockerfile')"
end

Expand All @@ -74,12 +74,12 @@ cli = Commander::Command.new do |cmd|
puts cmd.help
else
app = CachedDocker::App.new(
options.string["image_name"],
options.string["image_tag"],
options.string["build_params"],
options.string["cache_stage_target"],
options.string["dockerfile_path"],
options.bool["push"]
image_name: options.string["image_name"],
image_tag: options.string["image_tag"],
push: options.bool["push"],
dockerfile_path: options.string["dockerfile_path"],
build_params: options.string["build_params"],
cache_stage_target: options.string["cache_stage_target"],
)

if options.bool["print"]
Expand Down
9 changes: 5 additions & 4 deletions src/cached_docker/app.cr
Expand Up @@ -9,10 +9,11 @@ class CachedDocker::App
@push = true
getter :image_tag, :dockerfile_path, :build_params

def initialize(@image_name = "", @image_tag = "", @build_params = "", @cache_stage_target = "", @dockerfile_path = "", @push = true)
if @dockerfile_path == ""
@dockerfile_path = "./Dockerfile"
else
def initialize(*,
@image_name = "", @image_tag = "",
@push = true, @build_params = "",
@cache_stage_target = "", @dockerfile_path = "./Dockerfile")
if @dockerfile_path != "./Dockerfile"
@build_params = "#{@build_params} -f #{@dockerfile_path}"
end

Expand Down

0 comments on commit 45c169f

Please sign in to comment.