prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Add version command/flag to the Insights CLI 
  Add `version` command and `--version` flag/arg to print version info from `insights.get_nvr()`. 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `insights/command_parser.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 """
  3 Command Parser module
  4 ---------------------
  5 Implements the ``insights`` command line.  Each function is the first
  6 argument followed by the function specific arguments.  See USAGE text
  7 below.
  8 """
  9 from __future__ import print_function
  10 
  11 import argparse
  12 import sys
  13 
  14 USAGE = """insights <command> [<args>]
  15 Available commands:
  16   cat         Execute a spec and show the output
  17   collect     Collect all specs against the client and create an Insights archive.
  18   inspect     Execute component and shell out to ipython for evaluation.
  19   info        View info and docs for Insights Core components.
  20   ocpshell         Interactive evaluation of archives, directories, or individual yaml files.
  21   run         Run insights-core against host or an archive.
  22 """
  23 
  24 
  25 class InsightsCli(object):
  26     """
  27     Class to implement the cli module.
  28     Each command is called as a method of this class and all
  29     arg parsing is performed in the separate module that
  30     actually implements the command.  the args "insights command"
  31     are not passed to the submodule.
  32     """
  33 
  34     def __init__(self):
  35         parser = argparse.ArgumentParser(
  36             description="Insights Core command line execution",
  37             usage=USAGE)
  38         parser.add_argument('command', help='Insights Core command to run')
  39         args = parser.parse_args(sys.argv[1:2])
  40         if not hasattr(self, args.command):
  41             print('Unrecognized command')
  42             parser.print_help()
  43             sys.exit(1)
  44         # remove the sub-command arg from sys.argv
  45         sys.argv.pop(1)
  46         # Use dispatch pattern to execute command
  47         getattr(self, args.command)()
  48 
  49     def cat(self):
  50         from .tools.cat import main as cat_main
  51         cat_main()
  52 
  53     def collect(self):
  54         from .collect import main as collect_main
  55         collect_main()
  56 
  57     def info(self):
  58         from .tools.query import main as query_main
  59         query_main()
  60 
  61     def inspect(self):
  62         from .tools.insights_inspect import main as inspect_main
  63         inspect_main()
  64 
  65     def ocpshell(self):
  66         from .ocpshell import main as ocpshell_main
  67         ocpshell_main()
  68 
  69     def run(self):
  70         from insights import run
  71         if "" not in sys.path:
  72             sys.path.insert(0, "")
  73         run(print_summary=True)
  74 
  75 
  76 def fix_arg_dashes():
  77 
  78     en_dash = '\u2013'
  79     em_dash = '\u2014'
  80 
  81     # replace unicode (en dash and em dash) dashes from argument definitions that may have been copy
  82     # and pasted from another source
  83     i = 1
  84     for a in sys.argv[1:]:
  85         first = list(a)
  86         first[0] = first[0].replace(em_dash, "--").replace(en_dash, "-")
  87         sys.argv[i] = "".join(first)
  88         i += 1
  89 
  90 
  91 def main():
  92     fix_arg_dashes()
  93     try:
  94         InsightsCli()
  95     except SystemExit:
  96         raise
  97     except BaseException as ex:
  98         print(ex)
  99 
  100 
  101 if __name__ == "__main__":
  102     main()
  103
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/insights/command_parser.py b/insights/command_parser.py
  --- a/insights/command_parser.py
  +++ b/insights/command_parser.py
  @@ -19,6 +19,7 @@
     info        View info and docs for Insights Core components.
     ocpshell         Interactive evaluation of archives, directories, or individual yaml files.
     run         Run insights-core against host or an archive.
  +  version     Show Insights Core version information and exit.
   """
   
   
  @@ -36,6 +37,9 @@
               description="Insights Core command line execution",
               usage=USAGE)
           parser.add_argument('command', help='Insights Core command to run')
  +        parser.add_argument('--version', action='store_true', help='show Insights Core version information and exit')
  +        if self._parse_version_arg():
  +            self.version()
           args = parser.parse_args(sys.argv[1:2])
           if not hasattr(self, args.command):
               print('Unrecognized command')
  @@ -46,6 +50,12 @@
           # Use dispatch pattern to execute command
           getattr(self, args.command)()
   
  +    def _parse_version_arg(self):
  +        """
  +        Manually check for version argument/flag in cases when command is not provided.
  +        """
  +        return '--version' in sys.argv[1:3]
  +
       def cat(self):
           from .tools.cat import main as cat_main
           cat_main()
  @@ -72,6 +82,14 @@
               sys.path.insert(0, "")
           run(print_summary=True)
   
  +    def version(self):
  +        """
  +        Print version information (NVR) and exit.
  +        """
  +        from insights import get_nvr
  +        print(get_nvr())
  +        sys.exit()
  +
   
   def fix_arg_dashes():
  
verification_info: {"golden_diff": "diff --git a/insights/command_parser.py b/insights/command_parser.py\n--- a/insights/command_parser.py\n+++ b/insights/command_parser.py\n@@ -19,6 +19,7 @@\n   info        View info and docs for Insights Core components.\n   ocpshell         Interactive evaluation of archives, directories, or individual yaml files.\n   run         Run insights-core against host or an archive.\n+  version     Show Insights Core version information and exit.\n \"\"\"\n \n \n@@ -36,6 +37,9 @@\n             description=\"Insights Core command line execution\",\n             usage=USAGE)\n         parser.add_argument('command', help='Insights Core command to run')\n+        parser.add_argument('--version', action='store_true', help='show Insights Core version information and exit')\n+        if self._parse_version_arg():\n+            self.version()\n         args = parser.parse_args(sys.argv[1:2])\n         if not hasattr(self, args.command):\n             print('Unrecognized command')\n@@ -46,6 +50,12 @@\n         # Use dispatch pattern to execute command\n         getattr(self, args.command)()\n \n+    def _parse_version_arg(self):\n+        \"\"\"\n+        Manually check for version argument/flag in cases when command is not provided.\n+        \"\"\"\n+        return '--version' in sys.argv[1:3]\n+\n     def cat(self):\n         from .tools.cat import main as cat_main\n         cat_main()\n@@ -72,6 +82,14 @@\n             sys.path.insert(0, \"\")\n         run(print_summary=True)\n \n+    def version(self):\n+        \"\"\"\n+        Print version information (NVR) and exit.\n+        \"\"\"\n+        from insights import get_nvr\n+        print(get_nvr())\n+        sys.exit()\n+\n \n def fix_arg_dashes():\n", "issue": "Add version command/flag to the Insights CLI \nAdd `version` command and `--version` flag/arg to print version info from `insights.get_nvr()`. \n", "before_files": [{"content": "#!/usr/bin/env python\n\"\"\"\nCommand Parser module\n---------------------\nImplements the ``insights`` command line.  Each function is the first\nargument followed by the function specific arguments.  See USAGE text\nbelow.\n\"\"\"\nfrom __future__ import print_function\n\nimport argparse\nimport sys\n\nUSAGE = \"\"\"insights <command> [<args>]\nAvailable commands:\n  cat         Execute a spec and show the output\n  collect     Collect all specs against the client and create an Insights archive.\n  inspect     Execute component and shell out to ipython for evaluation.\n  info        View info and docs for Insights Core components.\n  ocpshell         Interactive evaluation of archives, directories, or individual yaml files.\n  run         Run insights-core against host or an archive.\n\"\"\"\n\n\nclass InsightsCli(object):\n    \"\"\"\n    Class to implement the cli module.\n    Each command is called as a method of this class and all\n    arg parsing is performed in the separate module that\n    actually implements the command.  the args \"insights command\"\n    are not passed to the submodule.\n    \"\"\"\n\n    def __init__(self):\n        parser = argparse.ArgumentParser(\n            description=\"Insights Core command line execution\",\n            usage=USAGE)\n        parser.add_argument('command', help='Insights Core command to run')\n        args = parser.parse_args(sys.argv[1:2])\n        if not hasattr(self, args.command):\n            print('Unrecognized command')\n            parser.print_help()\n            sys.exit(1)\n        # remove the sub-command arg from sys.argv\n        sys.argv.pop(1)\n        # Use dispatch pattern to execute command\n        getattr(self, args.command)()\n\n    def cat(self):\n        from .tools.cat import main as cat_main\n        cat_main()\n\n    def collect(self):\n        from .collect import main as collect_main\n        collect_main()\n\n    def info(self):\n        from .tools.query import main as query_main\n        query_main()\n\n    def inspect(self):\n        from .tools.insights_inspect import main as inspect_main\n        inspect_main()\n\n    def ocpshell(self):\n        from .ocpshell import main as ocpshell_main\n        ocpshell_main()\n\n    def run(self):\n        from insights import run\n        if \"\" not in sys.path:\n            sys.path.insert(0, \"\")\n        run(print_summary=True)\n\n\ndef fix_arg_dashes():\n\n    en_dash = '\\u2013'\n    em_dash = '\\u2014'\n\n    # replace unicode (en dash and em dash) dashes from argument definitions that may have been copy\n    # and pasted from another source\n    i = 1\n    for a in sys.argv[1:]:\n        first = list(a)\n        first[0] = first[0].replace(em_dash, \"--\").replace(en_dash, \"-\")\n        sys.argv[i] = \"\".join(first)\n        i += 1\n\n\ndef main():\n    fix_arg_dashes()\n    try:\n        InsightsCli()\n    except SystemExit:\n        raise\n    except BaseException as ex:\n        print(ex)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "insights/command_parser.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\"\"\"\nCommand Parser module\n---------------------\nImplements the ``insights`` command line.  Each function is the first\nargument followed by the function specific arguments.  See USAGE text\nbelow.\n\"\"\"\nfrom __future__ import print_function\n\nimport argparse\nimport sys\n\nUSAGE = \"\"\"insights <command> [<args>]\nAvailable commands:\n  cat         Execute a spec and show the output\n  collect     Collect all specs against the client and create an Insights archive.\n  inspect     Execute component and shell out to ipython for evaluation.\n  info        View info and docs for Insights Core components.\n  ocpshell         Interactive evaluation of archives, directories, or individual yaml files.\n  run         Run insights-core against host or an archive.\n  version     Show Insights Core version information and exit.\n\"\"\"\n\n\nclass InsightsCli(object):\n    \"\"\"\n    Class to implement the cli module.\n    Each command is called as a method of this class and all\n    arg parsing is performed in the separate module that\n    actually implements the command.  the args \"insights command\"\n    are not passed to the submodule.\n    \"\"\"\n\n    def __init__(self):\n        parser = argparse.ArgumentParser(\n            description=\"Insights Core command line execution\",\n            usage=USAGE)\n        parser.add_argument('command', help='Insights Core command to run')\n        parser.add_argument('--version', action='store_true', help='show Insights Core version information and exit')\n        if self._parse_version_arg():\n            self.version()\n        args = parser.parse_args(sys.argv[1:2])\n        if not hasattr(self, args.command):\n            print('Unrecognized command')\n            parser.print_help()\n            sys.exit(1)\n        # remove the sub-command arg from sys.argv\n        sys.argv.pop(1)\n        # Use dispatch pattern to execute command\n        getattr(self, args.command)()\n\n    def _parse_version_arg(self):\n        \"\"\"\n        Manually check for version argument/flag in cases when command is not provided.\n        \"\"\"\n        return '--version' in sys.argv[1:3]\n\n    def cat(self):\n        from .tools.cat import main as cat_main\n        cat_main()\n\n    def collect(self):\n        from .collect import main as collect_main\n        collect_main()\n\n    def info(self):\n        from .tools.query import main as query_main\n        query_main()\n\n    def inspect(self):\n        from .tools.insights_inspect import main as inspect_main\n        inspect_main()\n\n    def ocpshell(self):\n        from .ocpshell import main as ocpshell_main\n        ocpshell_main()\n\n    def run(self):\n        from insights import run\n        if \"\" not in sys.path:\n            sys.path.insert(0, \"\")\n        run(print_summary=True)\n\n    def version(self):\n        \"\"\"\n        Print version information (NVR) and exit.\n        \"\"\"\n        from insights import get_nvr\n        print(get_nvr())\n        sys.exit()\n\n\ndef fix_arg_dashes():\n\n    en_dash = '\\u2013'\n    em_dash = '\\u2014'\n\n    # replace unicode (en dash and em dash) dashes from argument definitions that may have been copy\n    # and pasted from another source\n    i = 1\n    for a in sys.argv[1:]:\n        first = list(a)\n        first[0] = first[0].replace(em_dash, \"--\").replace(en_dash, \"-\")\n        sys.argv[i] = \"\".join(first)\n        i += 1\n\n\ndef main():\n    fix_arg_dashes()\n    try:\n        InsightsCli()\n    except SystemExit:\n        raise\n    except BaseException as ex:\n        print(ex)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "insights/command_parser.py"}]}