diff --git a/lib/hammer_cli_katello/content_view_purge.rb b/lib/hammer_cli_katello/content_view_purge.rb index 6e5cb7d6..cd571210 100644 --- a/lib/hammer_cli_katello/content_view_purge.rb +++ b/lib/hammer_cli_katello/content_view_purge.rb @@ -7,9 +7,11 @@ class ContentViewPurgeCommand < HammerCLIKatello::Command command_name "purge" desc "Delete old versions of a content view" - option "--id", "ID", _("Content View numeric identifier") - option "--name", "NAME", _("Content View name") - option "--count", "COUNT", _("count of unused versions to keep"), + option "--id", "Id", _("Content View numeric identifier") + option "--name", "Name", _("Content View name") + option "--count", "Count", _("(deprecated) Number of versions to keep"), + :deprecated => true, format: HammerCLI::Options::Normalizers::Number.new + option "--versions-to-keep", "Versions to keep", _("Number of unused versions to keep"), default: 3, format: HammerCLI::Options::Normalizers::Number.new validate_options :before, 'IdResolution' do @@ -49,17 +51,23 @@ def option_sources end def execute - if option_count.negative? - output.print_error _("Invalid value for --count option: value must be 0 or greater.") + options['option_versions_to_keep'] = option_versions_to_keep + if option_versions_to_keep.negative? + output.print_error _("Invalid value for --versions-to-keep: value must be 0 or greater.") return HammerCLI::EX_USAGE end # Check if there is something to do - if option_count >= old_unused_versions.size + if option_count + warn _("The --count option is deprecated and will be removed in the next release.") + options['option_versions_to_keep'] = option_count + end + if options['option_versions_to_keep'] >= old_unused_versions.size output.print_error _("No versions to delete.") HammerCLI::EX_NOT_FOUND else - versions_to_purge = old_unused_versions.slice(0, old_unused_versions.size - option_count) + versions_to_purge = old_unused_versions.slice(0, old_unused_versions.size - + options['option_versions_to_keep']) versions_to_purge.each do |v| purge_version(v) diff --git a/test/functional/content_view/purge_test.rb b/test/functional/content_view/purge_test.rb index 48e1c1c9..148c844b 100644 --- a/test/functional/content_view/purge_test.rb +++ b/test/functional/content_view/purge_test.rb @@ -52,16 +52,27 @@ module HammerCLIKatello it 'fails gracefully if count <= 0' do api_expects_no_call - r = run_cmd(%w(content-view purge --id 2 --count -1)) - assert(r.err.include?('Invalid value for --count option'), 'Incorrect error message') + r = run_cmd(%w(content-view purge --id 2 --versions-to-keep -1)) + assert(r.err.include?('Invalid value for --versions-to-keep'), 'Incorrect error message') end - it 'fails gracefully when there are no versions to delete' do + it 'gives a deprecation warning with the --count option' do ex = api_expects(:content_view_versions, :index) ex = ex.with_params("content_view_id" => '2') ex.returns(versions) r = run_cmd(%w(content-view purge --id 2 --count 3)) + dep_warning = 'The --count option is deprecated and will be removed in the next release.' + _(r.err.lines.first.strip).must_equal(dep_warning) + assert(r.err.include?('No versions to delete.'), 'Incorrect error message') + end + + it 'fails gracefully when there are no versions to delete' do + ex = api_expects(:content_view_versions, :index) + ex = ex.with_params("content_view_id" => '2') + ex.returns(versions) + + r = run_cmd(%w(content-view purge --id 2 --versions-to-keep 3)) assert(r.err.include?('No versions to delete.'), 'Incorrect error message') end @@ -77,7 +88,7 @@ module HammerCLIKatello expect_foreman_task('3') end - run_cmd(%w(content-view purge --id 2 --count 0)) + run_cmd(%w(content-view purge --id 2 --versions-to-keep 0)) end it 'allows for async purge of versions' do @@ -91,7 +102,7 @@ module HammerCLIKatello ex.returns('id' => '3') end - run_cmd(%w(content-view purge --id 2 --count 0 --async)) + run_cmd(%w(content-view purge --id 2 --versions-to-keep 0 --async)) end end end