Skip to content

Commit

Permalink
Merge pull request #110 from larsewi/defmpf
Browse files Browse the repository at this point in the history
CFE-3812: cfbs init now prompts user whether to use default masterfiles
  • Loading branch information
olehermanse authored Apr 28, 2022
2 parents 5d910cc + 3f519b8 commit d4abb80
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 14 deletions.
25 changes: 23 additions & 2 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def init_command(index=None, non_interactive=False) -> int:
"name": name,
"type": "policy-set", # TODO: Prompt whether user wants to make a module
"description": description,
"build": [], # TODO: Prompt what masterfile user wants to add
"build": [],
}
if index:
config["index"] = index
Expand Down Expand Up @@ -193,7 +193,28 @@ def init_command(index=None, non_interactive=False) -> int:
print(
"Initialized an empty project called '{}' in '{}'".format(name, cfbs_filename())
)
print("To add your first module, type: cfbs add masterfiles")

"""
The CFBSConfig instance was initally created in main(). Back then
cfbs.json did not exist, thus the instance is empty. By manually deleting
this instance, a new instance will be created loading the now existing
cfbs.json.
"""
CFBSConfig.instance = None

if prompt_user(
"Do you wish to build on top of the default policy set, masterfiles? (Recommended)",
choices=YES_NO_CHOICES,
default="yes",
) in ("yes", "y"):
to_add = "masterfiles"
else:
to_add = prompt_user(
"Specify policy set to use instead (empty to skip)", default=""
)

if to_add:
return add_command([to_add])

return 0

Expand Down
2 changes: 1 addition & 1 deletion test/shell/002_add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ touch cfbs.json && rm cfbs.json
rm -rf .git

cfbs --non-interactive init
cfbs --non-interactive add masterfiles
cfbs --non-interactive add autorun
grep masterfiles cfbs.json
1 change: 0 additions & 1 deletion test/shell/003_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ touch cfbs.json && rm cfbs.json
rm -rf .git

cfbs --non-interactive init
cfbs --non-interactive add masterfiles
cfbs download

ls ~/.cfengine/cfbs/downloads/*
1 change: 0 additions & 1 deletion test/shell/004_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ touch cfbs.json && rm cfbs.json
rm -rf .git

cfbs --non-interactive init
cfbs --non-interactive add mpf
cfbs --non-interactive add autorun
cfbs --non-interactive add systemd
cfbs --non-interactive add git
Expand Down
2 changes: 1 addition & 1 deletion test/shell/005_alias.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ touch cfbs.json && rm cfbs.json
rm -rf .git

cfbs --non-interactive init
cfbs --non-interactive add mpf > output.log
cfbs --non-interactive add groups > output.log

grep "alias" output.log
grep "Added module" output.log
1 change: 0 additions & 1 deletion test/shell/007_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ rm -rf .git
rm -rf ~/.cfagent/inputs/

cfbs --non-interactive init
cfbs --non-interactive add mpf
cfbs --non-interactive add autorun
cfbs install

Expand Down
1 change: 0 additions & 1 deletion test/shell/008_remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ touch cfbs.json && rm cfbs.json
rm -rf .git

cfbs --non-interactive init
cfbs --non-interactive add masterfiles
grep '"name": "masterfiles"' cfbs.json
cfbs --non-interactive remove masterfiles --non-interactive
! grep '"name": "masterfiles"' cfbs.json
2 changes: 0 additions & 2 deletions test/shell/010_local_add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ rm -rf .git

cfbs --non-interactive init
cfbs status
cfbs --non-interactive add mpf
cfbs status
echo '
bundle agent test_bundle
{
Expand Down
1 change: 0 additions & 1 deletion test/shell/013_add_url_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ touch cfbs.json && rm cfbs.json
rm -rf .git

cfbs --non-interactive init
cfbs --non-interactive add masterfiles
cfbs --non-interactive add https://github.com/basvandervlies/cf_surfsara_lib@09e07dda690f5806d5f17be8e71d9fdcc51bbdf1

grep https://github.com/basvandervlies/cf_surfsara_lib cfbs.json
Expand Down
3 changes: 0 additions & 3 deletions test/shell/016_add_folders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ echo 'Hello
cfbs --non-interactive init
cfbs status

cfbs --non-interactive add mpf
cfbs status

cfbs --non-interactive add ./one
cfbs --non-interactive add ./two/
cfbs status
Expand Down

0 comments on commit d4abb80

Please sign in to comment.