summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-12-28 15:46:23 -0800
committerTim Smith <tsmith84@gmail.com>2020-12-30 11:43:03 -0800
commitc35cc213adc05ab2b3e7465dcdb33811fd2c17e7 (patch)
tree4fe78bb3e1e13eda86b026135b55ac67840490de
parentfe478e21ab62de19804c43d04b337c9443779e79 (diff)
downloadchef-c35cc213adc05ab2b3e7465dcdb33811fd2c17e7.tar.gz
Move FormattingOptions to its own file and remove duplication.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/knife/core/formatting_options.rb49
-rw-r--r--lib/chef/knife/core/node_presenter.rb25
-rw-r--r--lib/chef/knife/core/status_presenter.rb25
-rw-r--r--lib/chef/knife/node_show.rb3
-rw-r--r--lib/chef/knife/search.rb3
-rw-r--r--lib/chef/knife/status.rb4
6 files changed, 55 insertions, 54 deletions
diff --git a/lib/chef/knife/core/formatting_options.rb b/lib/chef/knife/core/formatting_options.rb
new file mode 100644
index 0000000000..cdee2c5989
--- /dev/null
+++ b/lib/chef/knife/core/formatting_options.rb
@@ -0,0 +1,49 @@
+#
+# Author:: Nicolas DUPEUX (<nicolas.dupeux@arkea.com>)
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class Chef
+ class Knife
+ module Core
+
+ # This module may be included into a knife subcommand class to automatically
+ # add configuration options used by the StatusPresenter and NodePresenter.
+ module FormattingOptions
+ # @private
+ # Would prefer to do this in a rational way, but can't be done b/c of
+ # Mixlib::CLI's design :(
+ def self.included(includer)
+ includer.class_eval do
+ option :medium_output,
+ short: "-m",
+ long: "--medium",
+ boolean: true,
+ default: false,
+ description: "Include normal attributes in the output"
+
+ option :long_output,
+ short: "-l",
+ long: "--long",
+ boolean: true,
+ default: false,
+ description: "Include all attributes in the output"
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/chef/knife/core/node_presenter.rb b/lib/chef/knife/core/node_presenter.rb
index 6690bc1075..8c948cf76c 100644
--- a/lib/chef/knife/core/node_presenter.rb
+++ b/lib/chef/knife/core/node_presenter.rb
@@ -23,31 +23,6 @@ class Chef
class Knife
module Core
- # This module may be included into a knife subcommand class to automatically
- # add configuration options used by the NodePresenter
- module NodeFormattingOptions
- # @private
- # Would prefer to do this in a rational way, but can't be done b/c of
- # Mixlib::CLI's design :(
- def self.included(includer)
- includer.class_eval do
- option :medium_output,
- short: "-m",
- long: "--medium",
- boolean: true,
- default: false,
- description: "Include normal attributes in the output"
-
- option :long_output,
- short: "-l",
- long: "--long",
- boolean: true,
- default: false,
- description: "Include all attributes in the output"
- end
- end
- end
-
# A customized presenter for Chef::Node objects. Supports variable-length
# output formats for displaying node data
class NodePresenter < GenericPresenter
diff --git a/lib/chef/knife/core/status_presenter.rb b/lib/chef/knife/core/status_presenter.rb
index 9a4ea76508..215e79f33b 100644
--- a/lib/chef/knife/core/status_presenter.rb
+++ b/lib/chef/knife/core/status_presenter.rb
@@ -23,31 +23,6 @@ class Chef
class Knife
module Core
- # This module may be included into a knife subcommand class to automatically
- # add configuration options used by the StatusPresenter
- module StatusFormattingOptions
- # @private
- # Would prefer to do this in a rational way, but can't be done b/c of
- # Mixlib::CLI's design :(
- def self.included(includer)
- includer.class_eval do
- option :medium_output,
- short: "-m",
- long: "--medium",
- boolean: true,
- default: false,
- description: "Include normal attributes in the output"
-
- option :long_output,
- short: "-l",
- long: "--long",
- boolean: true,
- default: false,
- description: "Include all attributes in the output"
- end
- end
- end
-
# A customized presenter for Chef::Node objects. Supports variable-length
# output formats for displaying node data
class StatusPresenter < GenericPresenter
diff --git a/lib/chef/knife/node_show.rb b/lib/chef/knife/node_show.rb
index 8ef06d8938..173348dc41 100644
--- a/lib/chef/knife/node_show.rb
+++ b/lib/chef/knife/node_show.rb
@@ -18,13 +18,14 @@
require_relative "../knife"
require_relative "core/node_presenter"
+require_relative "core/formatting_options"
require "chef-utils/dist" unless defined?(ChefUtils::Dist)
class Chef
class Knife
class NodeShow < Knife
- include Knife::Core::NodeFormattingOptions
+ include Knife::Core::FormattingOptions
include Knife::Core::MultiAttributeReturnOption
deps do
diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb
index 2feb8e6729..620cfb971d 100644
--- a/lib/chef/knife/search.rb
+++ b/lib/chef/knife/search.rb
@@ -18,6 +18,7 @@
require_relative "../knife"
require_relative "core/node_presenter"
+require_relative "core/formatting_options"
class Chef
class Knife
@@ -32,7 +33,7 @@ class Chef
require_relative "../search/query"
end
- include Knife::Core::NodeFormattingOptions
+ include Knife::Core::FormattingOptions
banner "knife search INDEX QUERY (options)"
diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb
index ea5dffdf6c..c52fb526a0 100644
--- a/lib/chef/knife/status.rb
+++ b/lib/chef/knife/status.rb
@@ -18,13 +18,13 @@
require_relative "../knife"
require_relative "core/status_presenter"
-require_relative "core/node_presenter"
+require_relative "core/formatting_options"
require "chef-utils/dist" unless defined?(ChefUtils::Dist)
class Chef
class Knife
class Status < Knife
- include Knife::Core::NodeFormattingOptions
+ include Knife::Core::FormattingOptions
deps do
require_relative "../search/query"