Skip to content

Commit 135cf58

Browse files
authored
Merge pull request #72 from ktaletsk/create-cmd-improvements
Improvements to 'create' CLI command: rename type arg and add error handling
2 parents 26f9c09 + 6c6d334 commit 135cf58

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/projspec/__main__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,26 @@ def create(type, path):
163163
(Path must be local, no storage_options)
164164
"""
165165
from projspec.proj import Project
166+
from projspec.proj.base import ProjectSpec, registry
166167

168+
if type not in registry:
169+
print(f"Unknown spec type: {type}")
170+
sys.exit(1)
167171
proj = Project(path)
168172
if type not in proj:
169-
files = proj.create(type)
173+
try:
174+
files = proj.create(type)
175+
except NotImplementedError:
176+
supported = sorted(
177+
name
178+
for name, cls in registry.items()
179+
if cls._create is not ProjectSpec._create
180+
)
181+
print(
182+
f"Spec type '{type}' does not support creation.\n"
183+
f"Types that support creation: {', '.join(supported)}"
184+
)
185+
sys.exit(1)
170186
for afile in files:
171187
print(afile)
172188
else:

src/projspec/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ def class_infos():
390390

391391
return {
392392
"specs": {
393-
name: {"doc": cls.__doc__, "link": cls.spec_doc}
393+
name: {
394+
"doc": cls.__doc__,
395+
"link": cls.spec_doc,
396+
"create": cls._create is not projspec.ProjectSpec._create,
397+
}
394398
for name, cls in projspec.proj.base.registry.items()
395399
},
396400
"content": {

tests/test_cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ def test_library(temp_conf_dir, capsys):
8181
main(["library", "delete", path], standalone_mode=False)
8282
main(["library", "list"], standalone_mode=False)
8383
assert capsys.readouterr().out == ""
84+
85+
86+
def test_create_cant(tmpdir, capsys):
87+
try:
88+
main(["create", "project_extra", str(tmpdir)], standalone_mode=False)
89+
except SystemExit:
90+
pass
91+
out = capsys.readouterr().out
92+
assert "does not support creation" in out
93+
assert "python_code" in out

0 commit comments

Comments
 (0)