Skip to content

Commit 162a41d

Browse files
authored
Merge pull request #281 from jakub-nt/CFE-4135
CFE-4135: Rework and expand `cfbs show` output
2 parents f70dcea + eeb9e46 commit 162a41d

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

JSON.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ The modules inside `build`, `provides`, and `index` use these fields:
204204
For modules in `provides`, must refer to other modules in `provides` or `index` (default one if not specified).
205205
For modules in `build`, must refer to other modules in `build`.
206206
- `added_by` (string): Information about how the module was added to `build`.
207-
Name of the module which added it as a dependency, or `"cfbs add"` if the user added the module itself.
207+
Name of the module which added it as a dependency, or name of the used command (`"cfbs add"`, `"cfbs init"`, `"cfbs convert"`) if the user added the module itself.
208208
Optional in `build` modules, not accepted in `provides` or `index`.
209209
- `steps` (array of strings): The operations performed (in order) to build the module.
210210
See the section below on build steps.

cfbs/commands.py

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -948,32 +948,39 @@ def help_command():
948948

949949

950950
def _print_module_info(data):
951+
def human_readable(key: str):
952+
if key == "repo":
953+
return "Repository"
954+
if key == "url":
955+
return "URL"
956+
return key.title().replace("_", " ")
957+
951958
ordered_keys = [
952959
"module",
953-
"version",
954-
"status",
955-
"by",
960+
"description",
956961
"tags",
957-
"repo",
962+
"dependencies",
958963
"index",
959-
"commit",
960964
"subdirectory",
961-
"dependencies",
962-
"added_by",
963-
"description",
965+
"url",
966+
"repo",
967+
"version",
968+
"commit",
969+
"by",
970+
"status",
964971
]
965972
for key in ordered_keys:
966973
if key in data:
967974
if key in ["tags", "dependencies"]:
968975
value = ", ".join(data[key])
969976
else:
970977
value = data[key]
971-
print("{}: {}".format(key.title().replace("_", " "), value))
978+
print("{}: {}".format(human_readable(key), value))
972979

973980

974981
@cfbs_command("show")
975982
@cfbs_command("info")
976-
def info_command(modules):
983+
def info_command(modules: List[str]):
977984
if not modules:
978985
raise CFBSExitError(
979986
"info/show command requires one or more module names as arguments"
@@ -996,22 +1003,53 @@ def info_command(modules):
9961003
if in_build:
9971004
# prefer information from the local source
9981005
data = next(m for m in build if m["name"] == module)
999-
data["status"] = "Added"
1006+
status_text = "Added"
10001007
elif module in index:
10011008
data = index[module]
10021009
if "alias" in data:
10031010
alias = module
10041011
module = data["alias"]
10051012
data = index[module]
1006-
data["status"] = "Added" if in_build else "Not added"
1013+
status_text = "Added" if in_build else "Not added"
10071014
else:
10081015
if not module.startswith("./"):
10091016
module = "./" + module
10101017
data = next((m for m in build if m["name"] == module), None)
10111018
if data is None:
10121019
print("Path {} exists but is not yet added as a module.".format(module))
10131020
continue
1014-
data["status"] = "Added"
1021+
status_text = "Added"
1022+
1023+
if status_text == "Added":
1024+
if "added_by" in data:
1025+
if data["added_by"] == "cfbs convert":
1026+
status_text = "Added during 'cfbs convert'"
1027+
elif data["added_by"] == "cfbs init":
1028+
if "url" in data:
1029+
status_text = "Added from URL (not from default index)"
1030+
else:
1031+
status_text = "Added from name"
1032+
status_text += " during 'cfbs init'"
1033+
elif data["added_by"].startswith("cfbs "):
1034+
# normally "cfbs add" - written more generally as a safer fallback
1035+
if "url" in data:
1036+
status_text = (
1037+
"Added by 'cfbs add <url>', not from default index"
1038+
)
1039+
else:
1040+
status_text = "Added by 'cfbs add <module-name>'"
1041+
else:
1042+
status_text = "Added by %s as a dependency" % data["added_by"]
1043+
1044+
if "input" in data:
1045+
input_path = os.path.join(data["name"], "input.json")
1046+
if not input_path.startswith("./"):
1047+
input_path = "./" + input_path
1048+
if os.path.isfile(input_path):
1049+
status_text += ", has input in %s" % input_path
1050+
else:
1051+
status_text += ", supports input (but has no input yet)"
1052+
data["status"] = status_text
10151053
data["module"] = (module + "({})".format(alias)) if alias else module
10161054
_print_module_info(data)
10171055
print() # extra line for ease of reading

cfbs/updates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def update_input_data(module, input_data) -> bool:
4242

4343
def _update_keys(input_def, input_data, keys):
4444
"""
45-
Update keys that can be safily updated in input data.
45+
Update keys that can be safely updated in input data.
4646
"""
4747
changes_made = False
4848
for key in keys:

0 commit comments

Comments
 (0)