Skip to content

Commit

Permalink
- use get_reference_fields for conan new
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
SSE4 committed Mar 29, 2021
1 parent d03a705 commit 5835feb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
12 changes: 5 additions & 7 deletions conans/client/cmd/new.py
Expand Up @@ -6,7 +6,7 @@
from conans import __version__ as client_version
from conans.client.cmd.new_ci import ci_get_files
from conans.errors import ConanException
from conans.model.ref import ConanFileReference
from conans.model.ref import ConanFileReference, get_reference_fields
from conans.util.files import load


Expand Down Expand Up @@ -322,13 +322,11 @@ def cmd_new(ref, header=False, pure_c=False, test=False, exports_sources=False,
gitlab_gcc_versions=None, gitlab_clang_versions=None,
circleci_gcc_versions=None, circleci_clang_versions=None, circleci_osx_versions=None,
template=None, cache=None, defines=None):


try:
tokens = ref.split("@")
name, version = tokens[0].split("/")
if len(tokens) == 2:
user, channel = tokens[1].split("/")
else:
user, channel = "user", "channel"
name, version, user, channel, revision = get_reference_fields(ref, user_channel_input=False)
# convert "package_name" -> "PackageName"
package_name = re.sub(r"(?:^|[\W_])(\w)", lambda x: x.group(1).upper(), name)
except ValueError:
raise ConanException("Bad parameter, please use full package name,"
Expand Down
18 changes: 18 additions & 0 deletions conans/test/integration/command/new_test.py
Expand Up @@ -386,3 +386,21 @@ def test_new_v2_cmake(self):
self.assertIn("CMakeToolchain", conanfile)
cmake = client.load("test_package/CMakeLists.txt")
self.assertIn("find_package", cmake)

def test_new_reference(self):
client = TestClient()
# full reference
client.run("new MyPackage/1.3@myuser/testing --template=v2_cmake")
conanfile = client.load("conanfile.py")
self.assertIn('name = "MyPackage"', conanfile)
self.assertIn('version = "1.3"', conanfile)
# no username, no channel (with @)
client.run("new MyPackage/1.3@ --template=v2_cmake")
conanfile = client.load("conanfile.py")
self.assertIn('version = "1.3"', conanfile)
self.assertIn('name = "MyPackage"', conanfile)
# no username, no channel (without @)
client.run("new MyPackage/1.3 --template=v2_cmake")
conanfile = client.load("conanfile.py")
self.assertIn('name = "MyPackage"', conanfile)
self.assertIn('version = "1.3"', conanfile)

0 comments on commit 5835feb

Please sign in to comment.