Skip to content

Commit

Permalink
feat(commands): move global --version to list command
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed May 28, 2022
1 parent 996a7ae commit 5f5f0f5
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 20 deletions.
11 changes: 0 additions & 11 deletions cleo/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@ def run(
return exit_code

def _run(self, io: IO) -> int:
if io.input.has_parameter_option(["--version", "-V"], True):
io.write_line(self.long_version)

return 0

definition = self.definition
input_definition = Definition()
for argument in definition.arguments:
Expand Down Expand Up @@ -564,12 +559,6 @@ def _default_definition(self) -> Definition:
"1 for normal output, 2 for more verbose output and 3 for debug."
),
),
Option(
"--version",
"-V",
flag=True,
description="Display this application version.",
),
Option("--ansi", flag=True, description="Force ANSI output."),
Option("--no-ansi", flag=True, description="Disable ANSI output."),
Option(
Expand Down
9 changes: 9 additions & 0 deletions cleo/commands/list_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cleo.io.inputs.argument import Argument

from ..helpers import option
from .command import Command


Expand All @@ -22,8 +23,16 @@ class ListCommand(Command):
arguments = [
Argument("namespace", required=False, description="The namespace name")
]
options = [
option("version", "V", "Display this application version.", flag=True),
]

def handle(self) -> int:
if self.option("version"):
self.io.write_line(self.application.long_version)

return 0

from cleo.descriptors.text_descriptor import TextDescriptor

TextDescriptor().describe(
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/completion/fixtures/bash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _my_function()

# completing for an option
if [[ ${cur} == --* ]] ; then
opts="--ansi --help --no-ansi --no-interaction --quiet --verbose --version"
opts="--ansi --help --no-ansi --no-interaction --quiet --verbose"

case "$com" in

Expand All @@ -38,7 +38,7 @@ _my_function()
;;

(list)
opts="${opts} "
opts="${opts} --version"
;;

esac
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/completion/fixtures/fish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ complete -c script -n '__fish_my_function_no_subcommand' -l no-ansi -d 'Disable
complete -c script -n '__fish_my_function_no_subcommand' -l no-interaction -d 'Do not ask any interactive question.'
complete -c script -n '__fish_my_function_no_subcommand' -l quiet -d 'Do not output any message.'
complete -c script -n '__fish_my_function_no_subcommand' -l verbose -d 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.'
complete -c script -n '__fish_my_function_no_subcommand' -l version -d 'Display this application version.'

# commands
complete -c script -f -n '__fish_my_function_no_subcommand' -a command:with:colons -d 'Test.'
Expand All @@ -34,3 +33,4 @@ complete -c script -A -n '__fish_seen_subcommand_from hello' -l option-without-d
# help

# list
complete -c script -A -n '__fish_seen_subcommand_from list' -l version -d 'Display this application version.'
4 changes: 2 additions & 2 deletions tests/commands/completion/fixtures/zsh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _my_function()

if [[ ${cur} == --* ]]; then
state="option"
opts=("--ansi:Force ANSI output." "--help:Display help for the given command. When no command is given display help for the list command." "--no-ansi:Disable ANSI output." "--no-interaction:Do not ask any interactive question." "--quiet:Do not output any message." "--verbose:Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug." "--version:Display this application version.")
opts=("--ansi:Force ANSI output." "--help:Display help for the given command. When no command is given display help for the list command." "--no-ansi:Disable ANSI output." "--no-interaction:Do not ask any interactive question." "--quiet:Do not output any message." "--verbose:Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.")
elif [[ $cur == $com ]]; then
state="command"
coms=("command\:with\:colons:Test." "hello:Complete me please." "help:Displays help for a command." "list:Lists commands.")
Expand All @@ -42,7 +42,7 @@ _my_function()
;;

(list)
opts+=()
opts+=("--version:Display this application version.")
;;

esac
Expand Down
16 changes: 16 additions & 0 deletions tests/commands/test_list_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from cleo.application import Application
from cleo.commands.list_command import ListCommand
from cleo.testers.command_tester import CommandTester


def test_version():
command = ListCommand()
command.set_application(Application("foo", "1.2.3"))

tester = CommandTester(command)
tester.execute("--version", decorated=True)

assert (
"\x1b[39;1mFoo\x1b[39;22m (version \x1b[36m1.2.3\x1b[39m)\n"
== tester.io.fetch_output()
)
1 change: 0 additions & 1 deletion tests/fixtures/application_run1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Usage:
Options:
-h, --help Display help for the given command. When no command is given display help for the list command.
-q, --quiet Do not output any message.
-V, --version Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
-n, --no-interaction Do not ask any interactive question.
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/application_run2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Arguments:
namespace The namespace name

Options:
-V, --version Display this application version.
-h, --help Display help for the given command. When no command is given display help for the list command.
-q, --quiet Do not output any message.
-V, --version Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
-n, --no-interaction Do not ask any interactive question.
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/application_run3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Arguments:
namespace The namespace name

Options:
-V, --version Display this application version.
-h, --help Display help for the given command. When no command is given display help for the list command.
-q, --quiet Do not output any message.
-V, --version Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
-n, --no-interaction Do not ask any interactive question.
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/application_run5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Arguments:
Options:
-h, --help Display help for the given command. When no command is given display help for the list command.
-q, --quiet Do not output any message.
-V, --version Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
-n, --no-interaction Do not ask any interactive question.
Expand Down

0 comments on commit 5f5f0f5

Please sign in to comment.