868e96d06a
Adds the ability to select a template which will create a new file in the CWD with the template name. Templates present in the "cmd/dagger/project/templates" directory are automatically embedded in the dagger binary when building and then listed in the `dagger project init` help output. Usage: dagger project init -t <template_name> One idea that we had while pairing on this is to eventually try improving this UX by extending the `dagger project` command by adding sub-commands like `dagger project templates [list, new, output, ...]`. Pair: gerhard Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
66 lines
1.4 KiB
Bash
66 lines
1.4 KiB
Bash
setup() {
|
|
load 'helpers'
|
|
|
|
common_setup
|
|
|
|
TEMPDIR=$(mktemp -d)
|
|
TEMPDIR2=$(mktemp -d)
|
|
}
|
|
|
|
@test "project init and update and info" {
|
|
cd "$TEMPDIR" || exit 1
|
|
|
|
"$DAGGER" project init ./ --name "github.com/foo/bar"
|
|
test -d ./cue.mod/pkg
|
|
test -d ./cue.mod/usr
|
|
test -f ./cue.mod/module.cue
|
|
contents=$(cat ./cue.mod/module.cue)
|
|
[ "$contents" == 'module: "github.com/foo/bar"' ]
|
|
|
|
# ensure old 0.1 style .gitignore is removed
|
|
printf "# generated by dagger\ndagger.lock" > .gitignore
|
|
|
|
"$DAGGER" project update
|
|
test -d ./cue.mod/pkg/dagger.io
|
|
test -d ./cue.mod/pkg/universe.dagger.io
|
|
test -f ./cue.mod/pkg/.gitattributes
|
|
run cat ./cue.mod/pkg/.gitattributes
|
|
assert_output --partial "generated by dagger"
|
|
|
|
test ! -f ./cue.mod/pkg/.gitignore
|
|
|
|
run "$DAGGER" project info
|
|
assert_success
|
|
assert_output --partial "Current dagger project in:"
|
|
assert_output --partial "$TEMPDIR"
|
|
|
|
cd "$TEMPDIR2" || exit
|
|
run "$DAGGER" project info
|
|
assert_failure
|
|
assert_output --partial "dagger project not found. Run \`dagger project init\`"
|
|
}
|
|
|
|
|
|
@test "project init with template" {
|
|
cd "$TEMPDIR" || exit 1
|
|
|
|
if test -f ./hello.cue
|
|
then
|
|
echo "./hello.cue should not exist"
|
|
exit 1
|
|
fi
|
|
|
|
run "$DAGGER" project init -t hello
|
|
|
|
assert_success
|
|
|
|
if test ! -f ./hello.cue
|
|
then
|
|
echo "./hello.cue file was not created by the template flag"
|
|
exit 1
|
|
fi
|
|
|
|
cd -
|
|
diff --unified "$TEMPDIR/hello.cue" "$TESTDIR/../cmd/dagger/cmd/project/templates/hello.cue"
|
|
}
|