Commit f43ef050 by Maria Soulountsi Committed by Steph Samson

Show project version if no argument provided for version command (#1191)

This changes the behavior of version command to show the current version
of the project if no arguments are provided.
parent 159123f3
......@@ -384,8 +384,9 @@ poetry lock
## version
This command bumps the version of the project
and writes the new version back to `pyproject.toml`
This command shows the current version of the project or bumps the version of
the project and writes the new version back to `pyproject.toml` if a valid
bump rule is provided.
The new version should ideally be a valid semver string or a valid bump rule:
`patch`, `minor`, `major`, `prepatch`, `preminor`, `premajor`, `prerelease`.
......
......@@ -6,20 +6,23 @@ from .command import Command
class VersionCommand(Command):
name = "version"
description = "Bumps the version of the project."
description = (
"Shows the version of the project or bumps it when a valid"
"bump rule is provided."
)
arguments = [
argument(
"version",
"The version number or the rule to update the version.",
optional=True,
default="patch",
)
]
help = """\
The version command bumps the version of the project
and writes the new version back to <comment>pyproject.toml</>.
The version command shows the current version of the project or bumps the version of
the project and writes the new version back to <comment>pyproject.toml</> if a valid
bump rule is provided.
The new version should ideally be a valid semver string or a valid bump rule:
patch, minor, major, prepatch, preminor, premajor, prerelease.
......@@ -38,7 +41,10 @@ patch, minor, major, prepatch, preminor, premajor, prerelease.
def handle(self):
version = self.argument("version")
version = self.increment_version(self.poetry.package.pretty_version, version)
if version:
version = self.increment_version(
self.poetry.package.pretty_version, version
)
self.line(
"Bumping version from <comment>{}</> to <info>{}</>".format(
......@@ -51,6 +57,12 @@ patch, minor, major, prepatch, preminor, premajor, prerelease.
poetry_content["version"] = version.text
self.poetry.file.write(content)
else:
self.line(
"Project (<comment>{}</>) version is <info>{}</>".format(
self.poetry.package.name, self.poetry.package.pretty_version
)
)
def increment_version(self, version, rule):
from poetry.semver import Version
......
import pytest
from cleo import CommandTester
from poetry.console.commands import VersionCommand
......@@ -36,3 +37,10 @@ def command():
)
def test_increment_version(version, rule, expected, command):
assert expected == command.increment_version(version, rule).text
def test_version_show(app):
command = app.find("version")
tester = CommandTester(command)
tester.execute()
assert "Project (simple-project) version is 1.2.3\n" == tester.io.fetch_output()
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