Skip to content
Permalink
Browse files

Merge pull request #945 from nanoc/deploy-target-arg

Allow specifying deploy target as argument
  • Loading branch information...
ddfreyne committed Sep 26, 2016
2 parents 755f762 + 61d2670 commit 686ef0eb5f01869f12065343cd0b3dcf94d31dac
Showing with 35 additions and 6 deletions.
  1. +13 −3 lib/nanoc/cli/commands/deploy.rb
  2. +22 −3 spec/nanoc/cli/commands/deploy_spec.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.
@@ -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
@@ -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(
@@ -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

0 comments on commit 686ef0e

Please sign in to comment.
You can’t perform that action at this time.