Skip to content

Commit

Permalink
feat: Add --no-load-default arg to the insights-run command (#3434)
Browse files Browse the repository at this point in the history
* Add --no-load-default arg, if this arg is passed the default plugins
  aren't loaded. This allows the execution of other projects without
  loading all the specs from core which can cause exceptions.
* Re-ordered the arguments so that they're in alphabetical order.
* Added some empty lines between some of the code below the args so that
  it's easier to read.

Signed-off-by: Ryan Blakley <[email protected]>
(cherry picked from commit 97fbefd)
  • Loading branch information
ryan-blakley authored and Sachin Patil committed Jun 9, 2022
1 parent 782344d commit 5d163d5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions insights/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,49 +274,55 @@ def _load_context(path):
def run(component=None, root=None, print_summary=False,
context=None, inventory=None, print_component=None):

load_default_plugins()

args = None
formatters = None

if print_summary:
import argparse
import logging
p = argparse.ArgumentParser(add_help=False)
p.add_argument("archive", nargs="?", help="Archive or directory to analyze.")
p.add_argument("-p", "--plugins", default="",
help="Comma-separated list without spaces of package(s) or module(s) containing plugins.")
p.add_argument("-b", "--bare",
help='Specify "spec=filename[,spec=filename,...]" to use the bare file for the spec',
default="")
help='Specify "spec=filename[,spec=filename,...]" to use the bare file for the spec', default="")
p.add_argument("-c", "--config", help="Configure components.")
p.add_argument("-f", "--format", help="Output format.", default="insights.formats.text")
p.add_argument("-i", "--inventory", help="Ansible inventory file for cluster analysis.")
p.add_argument("-k", "--pkg-query", help="Expression to select rules by package.")
p.add_argument("-v", "--verbose", help="Verbose output.", action="store_true")
p.add_argument("-f", "--format", help="Output format.", default="insights.formats.text")
p.add_argument("-p", "--plugins", default="",
help="Comma-separated list without spaces of package(s) or module(s) containing plugins.")
p.add_argument("-s", "--syslog", help="Log results to syslog.", action="store_true")
p.add_argument("--tags", help="Expression to select rules by tag.")
p.add_argument("-v", "--verbose", help="Verbose output.", action="store_true")
p.add_argument("-D", "--debug", help="Verbose debug output.", action="store_true")
p.add_argument("--context", help="Execution Context. Defaults to HostContext if an archive isn't passed.")
p.add_argument("--color", default="auto", choices=["always", "auto", "never"], metavar="[=WHEN]",
help="Choose if and how the color encoding is outputted. When is 'always', 'auto', or 'never'.")
p.add_argument("--context", help="Execution Context. Defaults to HostContext if an archive isn't passed.")
p.add_argument("--no-load-default", help="Don't load the default plugins.", action="store_true")
p.add_argument("--parallel", help="Execute rules in parallel.", action="store_true")
p.add_argument("--tags", help="Expression to select rules by tag.")

class Args(object):
pass

formatters = []
args = Args()
p.parse_known_args(namespace=args)
p = argparse.ArgumentParser(parents=[p])

if not args.no_load_default:
load_default_plugins()

global _COLOR
_COLOR = args.color
p = argparse.ArgumentParser(parents=[p])

args.format = "insights.formats._json" if args.format == "json" else args.format
args.format = "insights.formats._yaml" if args.format == "yaml" else args.format
fmt = args.format if "." in args.format else "insights.formats." + args.format

Formatter = dr.get_component(fmt)
if not Formatter or not isinstance(Formatter, FormatterClass):
dr.load_components(fmt, continue_on_error=False)
Formatter = get_formatter(fmt)

Formatter.configure(p)
p.parse_args(namespace=args)
formatter = Formatter(args)
Expand Down

0 comments on commit 5d163d5

Please sign in to comment.