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
14 changes: 6 additions & 8 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
perform_build,
)
from cfbs.cfbs_config import CFBSConfig, CFBSReturnWithoutCommit
from cfbs.validate import validate_config
from cfbs.validate import validate_config, validate_config_raise_exceptions
from cfbs.internal_file_management import (
clone_url_repo,
SUPPORTED_URI_SCHEMES,
Expand Down Expand Up @@ -295,9 +295,7 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int:
@cfbs_command("status")
def status_command() -> int:
config = CFBSConfig.get_instance()
if validate_config(config, empty_build_list_ok=True) != 0:
return 1
config.warn_about_unknown_keys()
validate_config_raise_exceptions(config, empty_build_list_ok=True)
print("Name: %s" % config["name"])
print("Description: %s" % config["description"])
print("File: %s" % cfbs_filename())
Expand Down Expand Up @@ -392,7 +390,7 @@ def add_command(
checksum=None,
) -> Union[Result, int]:
config = CFBSConfig.get_instance()
config.warn_about_unknown_keys()
validate_config_raise_exceptions(config, empty_build_list_ok=True)
r = config.add_command(to_add, added_by, checksum)
config.save()
return r
Expand All @@ -402,7 +400,7 @@ def add_command(
@commit_after_command("Removed module%s %s", [PLURAL_S, FIRST_ARG_SLIST])
def remove_command(to_remove: List[str]):
config = CFBSConfig.get_instance()
config.warn_about_unknown_keys()
validate_config_raise_exceptions(config, empty_build_list_ok=True)
if "build" not in config:
raise CFBSExitError(
'Cannot remove any modules because the "build" key is missing from cfbs.json'
Expand Down Expand Up @@ -570,7 +568,7 @@ def _someone_needs_me(this) -> bool:
@commit_after_command("Updated module%s", [PLURAL_S])
def update_command(to_update) -> Result:
config = CFBSConfig.get_instance()
config.warn_about_unknown_keys()
validate_config_raise_exceptions(config, empty_build_list_ok=True)
build = config["build"]

# Update all modules in build if none specified
Expand Down Expand Up @@ -1046,7 +1044,7 @@ def analyze_command(
@commit_after_command("Added input for module%s", [PLURAL_S])
def input_command(args, input_from="cfbs input") -> Result:
config = CFBSConfig.get_instance()
config.warn_about_unknown_keys()
validate_config_raise_exceptions(config, empty_build_list_ok=True)
do_commit = False
files_to_commit = []
for module_name in args:
Expand Down
1 change: 1 addition & 0 deletions tests/shell/018_update_input_one_variable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rm -rf .git
rm -rf example-module
cp -r ../shell/018_update_input_one_variable/example-module .
cp ../shell/018_update_input_one_variable/example-cfbs.json cfbs.json
cfbs validate

cfbs --loglevel=debug --non-interactive update
grep '"label": "Filepath"' example-module/input.json
Expand Down
14 changes: 8 additions & 6 deletions tests/shell/018_update_input_one_variable/example-cfbs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"index": {
"example-module": {
"description": "Example module",
"tags": [],
"repo": "https://github.com/example-user/example-modules.git",
"by": "https://github.com/example-user",
"version": "1.0.1",
Expand All @@ -15,20 +16,21 @@
{
"type": "string",
"variable": "filename",
"namespace": "example_module",
"bundle": "example_module",
"label": "Filepath",
"question": "Path of file?",
"default": "/tmp/test.txt"
}
],
"steps": [
"input ./input.json def.json"
]
"steps": ["input ./input.json def.json"]
}
},
"build": [
{
"name": "example-module",
"description": "Example module",
"tags": [],
"repo": "https://github.com/example-user/example-modules.git",
"commit": "0000000000000000000000000000000000000000",
"by": "https://github.com/example-user",
Expand All @@ -38,14 +40,14 @@
{
"type": "string",
"variable": "filename",
"namespace": "example_module",
"bundle": "example_module",
"label": "Filename",
"question": "What file should this module create?",
"default": "/tmp/example.txt"
}
],
"steps": [
"input ./input.json def.json"
],
"steps": ["input ./input.json def.json"],
"added_by": "cfbs add"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"type": "string",
"variable": "filename",
"namespace": "example_module",
"bundle": "example_module",
"label": "Filename",
"question": "What file should this module create?",
"response": "/tmp/create-single-file.txt",
Expand Down
1 change: 1 addition & 0 deletions tests/shell/019_update_input_two_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rm -rf .git
rm -rf example-module
cp -r ../shell/019_update_input_two_variables/example-module .
cp ../shell/019_update_input_two_variables/example-cfbs.json cfbs.json
cfbs validate

cfbs --loglevel=debug --non-interactive update
grep '"label": "Path"' example-module/input.json
Expand Down
21 changes: 13 additions & 8 deletions tests/shell/019_update_input_two_variables/example-cfbs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"index": {
"example-module": {
"description": "Example module",
"tags": [],
"repo": "https://github.com/larsewi/cfbs-test-modules.git",
"commit": "3827a0da69d73ec2f973660d3c640b33cad58655",
"by": "https://github.com/larsewi",
Expand All @@ -15,52 +16,56 @@
{
"type": "string",
"variable": "filename",
"namespace": "example_module",
"bundle": "example_module",
"label": "Path",
"question": "Path of file?",
"default": "/tmp/test.txt"
},
{
"type": "string",
"variable": "content",
"namespace": "example_module",
"bundle": "example_module",
"label": "Contents",
"question": "File contents?",
"default" : "Hello CFEngine!"
"default": "Hello CFEngine!"
}
],
"steps": [
"input ./input.json def.json"
]
"steps": ["input ./input.json def.json"]
}
},
"build": [
{
"name": "example-module",
"description": "Example module",
"tags": [],
"repo": "https://github.com/example-user/example-modules.git",
"commit": "0000000000000000000000000000000000000000",
"by": "https://github.com/example-user",
"version": "1.0.0",
"subdirectory": "example-module",
"dependencies": ["autorun"],
"input": [
{
"type": "string",
"variable": "filename",
"namespace": "example_module",
"bundle": "example_module",
"label": "Filename",
"question": "What file should this module create?",
"default": "/tmp/example.txt"
},
{
"type": "string",
"variable": "content",
"namespace": "example_module",
"bundle": "example_module",
"label": "Content",
"question": "What content should this file have?",
"default": "Bye CFEngine!"
}
],
"steps": [
"input ./input.json def.json"
],
"steps": ["input ./input.json def.json"],
"added_by": "cfbs add"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"type": "string",
"variable": "filename",
"namespace": "example_module",
"bundle": "example_module",
"label": "Filename",
"question": "What file should this module create?",
"default": "/tmp/example.txt",
Expand All @@ -10,6 +12,8 @@
{
"type": "string",
"variable": "content",
"namespace": "example_module",
"bundle": "example_module",
"label": "Content",
"question": "What content should this file have?",
"default": "Bye CFEngine!",
Expand Down
1 change: 1 addition & 0 deletions tests/shell/020_update_input_list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rm -rf .git
rm -rf example-module
cp -r ../shell/020_update_input_list/example-module .
cp ../shell/020_update_input_list/example-cfbs.json cfbs.json
cfbs validate

cfbs --loglevel=debug --non-interactive update
grep '"label": "Filepaths"' example-module/input.json
Expand Down
14 changes: 8 additions & 6 deletions tests/shell/020_update_input_list/example-cfbs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"index": {
"example-module": {
"description": "Example module",
"tags": [],
"repo": "https://github.com/example-user/example-modules.git",
"commit": "3827a0da69d73ec2f973660d3c640b33cad58655",
"by": "https://github.com/example-user",
Expand All @@ -15,6 +16,8 @@
{
"type": "list",
"variable": "files",
"namespace": "example_module",
"bundle": "example_module",
"label": "Filepaths",
"subtype": {
"type": "string",
Expand All @@ -25,15 +28,14 @@
"while": "Create another file?"
}
],
"steps": [
"input ./input.json def.json"
]
"steps": ["input ./input.json def.json"]
}
},
"build": [
{
"name": "example-module",
"description": "Example module",
"tags": [],
"commit": "0000000000000000000000000000000000000000",
"by": "https://github.com/example-user",
"version": "1.0.0",
Expand All @@ -42,6 +44,8 @@
{
"type": "list",
"variable": "files",
"namespace": "example_module",
"bundle": "example_module",
"label": "Files",
"subtype": {
"type": "string",
Expand All @@ -52,9 +56,7 @@
"while": "Do you want to create another file?"
}
],
"steps": [
"input ./input.json def.json"
],
"steps": ["input ./input.json def.json"],
"added_by": "cfbs add"
}
]
Expand Down
2 changes: 2 additions & 0 deletions tests/shell/020_update_input_list/example-module/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"type": "list",
"variable": "files",
"namespace": "example_module",
"bundle": "example_module",
"label": "Files",
"subtype": {
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions tests/shell/021_update_input_list_with_keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rm -rf .git
rm -rf example-module
cp -r ../shell/021_update_input_list_with_keys/example-module .
cp ../shell/021_update_input_list_with_keys/example-cfbs.json cfbs.json
cfbs validate

cfbs --loglevel=debug --non-interactive update
grep '"while": "Create another file?"' example-module/input.json
Expand Down
14 changes: 8 additions & 6 deletions tests/shell/021_update_input_list_with_keys/example-cfbs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"index": {
"example-module": {
"description": "Example module",
"tags": [],
"repo": "https://github.com/example-user/example-modules.git",
"by": "https://github.com/example-user",
"version": "1.0.1",
Expand All @@ -15,6 +16,8 @@
{
"type": "list",
"variable": "files",
"namespace": "example_module",
"bundle": "example_module",
"label": "Files",
"subtype": [
{
Expand All @@ -35,15 +38,14 @@
"while": "Create another file?"
}
],
"steps": [
"input ./input.json def.json"
]
"steps": ["input ./input.json def.json"]
}
},
"build": [
{
"name": "example-module",
"description": "Example module",
"tags": [],
"commit": "0000000000000000000000000000000000000000",
"by": "https://github.com/example-user",
"version": "1.0.0",
Expand All @@ -52,6 +54,8 @@
{
"type": "list",
"variable": "files",
"namespace": "example_module",
"bundle": "example_module",
"label": "Files",
"subtype": [
{
Expand All @@ -72,9 +76,7 @@
"while": "Do you want to create another file?"
}
],
"steps": [
"input ./input.json def.json"
],
"steps": ["input ./input.json def.json"],
"added_by": "cfbs add"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"type": "list",
"variable": "files",
"namespace": "example_module",
"bundle": "example_module",
"label": "Files",
"subtype": [
{
Expand Down
1 change: 1 addition & 0 deletions tests/shell/022_update_input_fail_variable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rm -rf .git
rm -rf example-module
cp -r ../shell/022_update_input_fail_variable/example-module .
cp ../shell/022_update_input_fail_variable/example-cfbs.json cfbs.json
cfbs validate

cfbs --loglevel=debug --non-interactive update > output.log 2>&1
grep "Failed to update input data for module 'example-module'" ./output.log
Loading