Commit ca0032a4 authored by S. Zeid's avatar S. Zeid

[cli/engine/commands/shell] Add --version/-V flag (and CLI.version attribute)

parent 22009e58
......@@ -39,6 +39,7 @@ import types
from ..app import App
from ..applist import AppList
from ..container import ContainerRoot
from .. import __version__ as pkg_version
from engine import CLI, CLIError, Command, output, debug
......@@ -52,6 +53,7 @@ class CLI(CLI):
description = __doc__
easter_eggs = True
program = "iosapplist"
version = pkg_version
app_class = App
app_root = None
......
......@@ -78,6 +78,7 @@ def make_CLI_class():
description = None
easter_eggs = False
program = None
version = None
def start(self, argv, default=None.__class__):
argv = (["shell"] if not self.__started_any else []) + argv
......
......@@ -69,6 +69,7 @@ class ShellCommand(Command):
usage = "[options [...]] [command [args [...]]]"
__is_shell = True
__want_help = False
__robot_easter_egg_triggers = ("true", "yes", "on", "y", "1")
__use_real_output_format = True
......@@ -81,14 +82,14 @@ class ShellCommand(Command):
if not self.__is_shell:
p.usage = self.usage
p.description = cli.description
if self.__is_shell:
if self.__is_shell or self.__want_help:
p.add_argument("--help", "-h", action="store_true",
help='show this help and exit')
if self.easter_eggs:
p.add_argument("--hep", action="store_true", help=argparse.SUPPRESS)
p.add_argument("--robot", default="", metavar='<format>',
help='Produce output suitable for robots.'
' Format should be "plist" or "json".')
if self.__want_help and not self.__is_shell and getattr(cli, "version", None):
p.add_argument("--version", "-V", action="store_true",
help="show program's version number and exit")
if self.__is_shell:
p.add_argument("--ps1", default="> ",
help='The string to use to prompt for shell input ("> " by'
......@@ -97,8 +98,11 @@ class ShellCommand(Command):
help='Prompt for and terminate shell input with a null byte'
' instead of, respectively, ps1 and a newline. Useful'
' in conjunction with --robot.')
p.add_argument("--robot", default="", metavar='<format>',
help='Produce output suitable for robots.'
' Format should be "plist" or "json".')
p.formatter_class = argparse.RawDescriptionHelpFormatter
if not self.__is_shell:
if not self.__is_shell and self.__want_help:
p.epilog = "commands"
if cli.default_command:
p.epilog += " (default is `%s`)" % cli.default_command
......@@ -169,6 +173,11 @@ class ShellCommand(Command):
if help_flag or (help_arg and not self.__is_shell):
yield self.do_help(cli)
if not self.__is_shell:
if len(self.extra) and self.extra[0] in ("-V", "--version"):
yield output.normal(self.version_string(cli))
raise StopIteration(0)
build = ""
real_command = None
while True:
......@@ -216,6 +225,10 @@ class ShellCommand(Command):
if self.easter_eggs and argv[0] == "hep":
argv[0] = "--hep"
argv = ["sh"] + argv
if argv[0] == "version":
real_command = False
message = self.version_string(cli)
output.OutputCommand(cli).run([self.argv[0], "0", message])
elif not len(argv) and one_command == False:
continue
r = 127
......@@ -270,6 +283,10 @@ class ShellCommand(Command):
cmd = self.__class__(cli)
cmd.argv = [self.argv[0], "--help"]
cmd.__is_shell = not for_program
cmd.__want_help = True
for i in cmd._parse_args(cli):
pass
return cmd.arg_parser.format_help()
def version_string(self, cli):
return "%s %s" % (str(cli.program), str(cli.version))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment