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 specifying deploy target as argument #945

Merged
merged 1 commit into from Sep 26, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/nanoc/cli/commands/deploy.rb
@@ -1,4 +1,4 @@
usage 'deploy [options]'
usage 'deploy [target] [options]'
summary 'deploy the compiled site'
description "
Deploys the compiled site. The compiled site contents in the output directory will be uploaded to the destination, which is specified using the `--target` option.
Expand Down Expand Up @@ -60,8 +60,18 @@ def deploy_config
raise Nanoc::Int::Errors::GenericTrivial, 'The site has no deployment configurations.'
end

target = options.fetch(:target, :default).to_sym
deploy_configs.fetch(target) do
if arguments.length > 1
raise Nanoc::Int::Errors::GenericTrivial, "usage: #{command.usage}"
end

target_from_arguments = arguments[0]
target_from_options = options.fetch(:target, nil)
if target_from_arguments && target_from_options
raise Nanoc::Int::Errors::GenericTrivial, 'Only one deployment target can be specified on the command line.'
end

target = target_from_arguments || target_from_options || :default
deploy_configs.fetch(target.to_sym) do
raise Nanoc::Int::Errors::GenericTrivial, "The site has no deployment configuration named `#{target}`."
end
end
Expand Down
25 changes: 22 additions & 3 deletions spec/nanoc/cli/commands/deploy_spec.rb
Expand Up @@ -250,9 +250,7 @@
end
end

context 'non-default target' do
let(:command) { %w(deploy --target production) }

shared_examples 'deploy with non-default target' do
context 'requested deploy config does not exist' do
it 'errors' do
expect { run }.to raise_error(
Expand Down Expand Up @@ -304,6 +302,27 @@
end
end
end

context 'non-default target, specified as argument' do
let(:command) { %w(deploy production) }
include_examples 'deploy with non-default target'
end

context 'non-default target, specified as option (--target)' do
let(:command) { %w(deploy --target production) }
include_examples 'deploy with non-default target'
end

context 'multiple targets specified' do
let(:command) { %w(deploy --target staging production) }

it 'errors' do
expect { run }.to raise_error(
Nanoc::Int::Errors::GenericTrivial,
'Only one deployment target can be specified on the command line.',
)
end
end
end
end
end
Expand Down