Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ The modules inside `build`, `provides`, and `index` use these fields:
For modules in `provides`, must refer to other modules in `provides` or `index` (default one if not specified).
For modules in `build`, must refer to other modules in `build`.
- `added_by` (string): Information about how the module was added to `build`.
Name of the module which added it as a dependency, or `"cfbs add"` if the user added the module itself.
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.
Optional in `build` modules, not accepted in `provides` or `index`.
- `steps` (array of strings): The operations performed (in order) to build the module.
See the section below on build steps.
Expand Down
64 changes: 51 additions & 13 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,32 +948,39 @@ def help_command():


def _print_module_info(data):
def human_readable(key: str):
if key == "repo":
return "Repository"
if key == "url":
return "URL"
return key.title().replace("_", " ")

ordered_keys = [
"module",
"version",
"status",
"by",
"description",
"tags",
"repo",
"dependencies",
"index",
"commit",
"subdirectory",
"dependencies",
"added_by",
"description",
"url",
"repo",
"version",
"commit",
"by",
"status",
]
for key in ordered_keys:
if key in data:
if key in ["tags", "dependencies"]:
value = ", ".join(data[key])
else:
value = data[key]
print("{}: {}".format(key.title().replace("_", " "), value))
print("{}: {}".format(human_readable(key), value))


@cfbs_command("show")
@cfbs_command("info")
def info_command(modules):
def info_command(modules: List[str]):
if not modules:
raise CFBSExitError(
"info/show command requires one or more module names as arguments"
Expand All @@ -996,22 +1003,53 @@ def info_command(modules):
if in_build:
# prefer information from the local source
data = next(m for m in build if m["name"] == module)
data["status"] = "Added"
status_text = "Added"
elif module in index:
data = index[module]
if "alias" in data:
alias = module
module = data["alias"]
data = index[module]
data["status"] = "Added" if in_build else "Not added"
status_text = "Added" if in_build else "Not added"
else:
if not module.startswith("./"):
module = "./" + module
data = next((m for m in build if m["name"] == module), None)
if data is None:
print("Path {} exists but is not yet added as a module.".format(module))
continue
data["status"] = "Added"
status_text = "Added"

if status_text == "Added":
if "added_by" in data:
if data["added_by"] == "cfbs convert":
status_text = "Added during 'cfbs convert'"
elif data["added_by"] == "cfbs init":
if "url" in data:
status_text = "Added from URL (not from default index)"
else:
status_text = "Added from name"
status_text += " during 'cfbs init'"
elif data["added_by"].startswith("cfbs "):
# normally "cfbs add" - written more generally as a safer fallback
if "url" in data:
status_text = (
"Added by 'cfbs add <url>', not from default index"
)
else:
status_text = "Added by 'cfbs add <module-name>'"
else:
status_text = "Added by %s as a dependency" % data["added_by"]

if "input" in data:
input_path = os.path.join(data["name"], "input.json")
if not input_path.startswith("./"):
input_path = "./" + input_path
if os.path.isfile(input_path):
status_text += ", has input in %s" % input_path
else:
status_text += ", supports input (but has no input yet)"
data["status"] = status_text
data["module"] = (module + "({})".format(alias)) if alias else module
_print_module_info(data)
print() # extra line for ease of reading
Expand Down
2 changes: 1 addition & 1 deletion cfbs/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def update_input_data(module, input_data) -> bool:

def _update_keys(input_def, input_data, keys):
"""
Update keys that can be safily updated in input data.
Update keys that can be safely updated in input data.
"""
changes_made = False
for key in keys:
Expand Down