-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |