Skip to content

Commit

Permalink
(PDK-771) Wireframe pdk update CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Feb 9, 2018
1 parent 273f0fe commit 6c0edcd
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pdk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def self.full_interview_option(dsl)
require 'pdk/cli/convert'
require 'pdk/cli/new'
require 'pdk/cli/test'
require 'pdk/cli/update'
require 'pdk/cli/validate'
require 'pdk/cli/module'

Expand Down
29 changes: 29 additions & 0 deletions lib/pdk/cli/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'pdk/cli/util'

module PDK::CLI
@update_cmd = @base_cmd.define_command do
name 'update'
usage _('update [options]')
summary _('Update a module that has been created by or converted for use by PDK.')

flag nil, :noop, _('Do not update the module, just output what would be done.')
flag nil, :force, _('Update the module automatically, with no prompts.')

be_hidden

run do |opts, _args, _cmd|
require 'pdk/module/update'

PDK::CLI::Util.ensure_in_module!(
message: _('`pdk update` can only be run from inside a valid module directory.'),
log_level: :info,
)

if opts[:noop] && opts[:force]
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when updating a module')
end

PDK::Module::Update.invoke(opts)
end
end
end
9 changes: 9 additions & 0 deletions lib/pdk/module/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module PDK
module Module
class Update
def self.invoke(_opts = {})
# TODO: do some updatey things
end
end
end
end
61 changes: 61 additions & 0 deletions spec/unit/pdk/cli/update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'spec_helper'

describe 'PDK::CLI update' do
let(:help_text) { a_string_matching(%r{^USAGE\s+pdk update}m) }

context 'when not run from inside a module' do
include_context 'run outside module'

it 'exits with an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{must be run from inside a valid module}))

expect {
PDK::CLI.run(%w[update])
}.to raise_error(SystemExit) { |error|
expect(error.status).not_to eq(0)
}
end
end

context 'when run from inside a module' do
before(:each) do
allow(PDK::Util).to receive(:module_root).and_return('/path/to/test/module')
end

context 'and provided no flags' do
it 'invokes the updater with no options' do
expect(PDK::Module::Update).to receive(:invoke).with({})

PDK::CLI.run(%w[update])
end
end

context 'and the --noop flag has been passed' do
it 'passes the noop option through to the updater' do
expect(PDK::Module::Update).to receive(:invoke).with(noop: true)

PDK::CLI.run(%w[update --noop])
end
end

context 'and the --force flag has been passed' do
it 'passes the force option through to the updater' do
expect(PDK::Module::Update).to receive(:invoke).with(force: true)

PDK::CLI.run(%w[update --force])
end
end

context 'and the --force and --noop flags have been passed' do
it 'exits with an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{can not specify --noop and --force}i))

expect {
PDK::CLI.run(%w[update --noop --force])
}.to raise_error(SystemExit) { |error|
expect(error.status).not_to eq(0)
}
end
end
end
end

0 comments on commit 6c0edcd

Please sign in to comment.