Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to setup compose run options #25

Merged
merged 1 commit into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spec/app/dip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interaction:
irb:
service: app
command: irb
compose_run_options:
- no-deps
- workdir='/app'

bundle:
service: app
Expand Down
6 changes: 6 additions & 0 deletions spec/dip/commands/run_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ describe Dip::Cli::Commands::Run do
cmd.out.gets_to_end.should contain("compose run --rm app bundle exec rspec spec/test_spec.rb")
end
end

it "runs command with compose options" do
Dip::Cli::Commands::Run.run(%w(irb)) do |cmd|
cmd.out.gets_to_end.should contain("compose run --rm --no-deps --workdir='/app'")
end
end
end
end
4 changes: 2 additions & 2 deletions src/dip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module Dip
end

def self.test?
ENV["DIP_ENV"] == "test"
ENV.fetch("DIP_ENV", nil) == "test"
end

def self.debug?
ENV["DIP_ENV"] == "debug"
ENV.fetch("DIP_ENV", nil) == "debug"
end

def self.reset!
Expand Down
9 changes: 8 additions & 1 deletion src/dip/commands/run.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ module Dip::Cli::Commands

cmd_options = (unparsed_args || %w()).join(" ")

exec_cmd!("#{Process.executable_path} compose run --rm #{service_arg} #{cmd_arg} #{cmd_options}".strip)
run_opts = ["rm"]
if opts = command.compose_run_options
run_opts.concat(opts)
end

run_opts = run_opts.map { |o| "--#{o}" }.join(" ")

exec_cmd!("#{Process.executable_path} compose run #{run_opts} #{service_arg} #{cmd_arg} #{cmd_options}".strip)
end
end
end
4 changes: 4 additions & 0 deletions src/dip/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ module Dip
subcommands: {
type: Hash(String, ::Dip::Config::Subcommand),
nilable: true
},
compose_run_options: {
type: Array(String),
nilable: true
}
)
end
Expand Down