From 90d3724d6aa59ba49f1877f95a7a8a6fc33584cf Mon Sep 17 00:00:00 2001 From: Kenneth Lear Date: Mon, 4 Apr 2022 22:13:45 -0400 Subject: [PATCH 1/5] feat: Adding project info command to find where project is located Signed-off-by: Kenneth Lear --- cmd/dagger/cmd/project/info.go | 34 +++++++++++++++++++++++++++ cmd/dagger/cmd/project/projectroot.go | 1 + tests/project.bats | 8 +++++-- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 cmd/dagger/cmd/project/info.go diff --git a/cmd/dagger/cmd/project/info.go b/cmd/dagger/cmd/project/info.go new file mode 100644 index 00000000..c536fb5f --- /dev/null +++ b/cmd/dagger/cmd/project/info.go @@ -0,0 +1,34 @@ +package project + +import ( + "fmt" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/pkg" +) + +var infoCmd = &cobra.Command{ + Use: "info", + Short: "Lists project location on file system", + Args: cobra.MaximumNArgs(1), + PreRun: func(cmd *cobra.Command, args []string) { + // Fix Viper bug for duplicate flags: + // https://github.com/spf13/viper/issues/233 + if err := viper.BindPFlags(cmd.Flags()); err != nil { + panic(err) + } + }, + Run: func(cmd *cobra.Command, args []string) { + lg := logger.New() + + cueModPath, cueModExists := pkg.GetCueModParent() + if !cueModExists { + lg.Fatal().Msg("dagger project not found. Run `dagger project init`") + } + + fmt.Println(fmt.Sprintf("Current dagger project in: %s", cueModPath)) + + // TODO: find available plans and if they load successfully + }, +} diff --git a/cmd/dagger/cmd/project/projectroot.go b/cmd/dagger/cmd/project/projectroot.go index 386ebe0a..9d2d0380 100644 --- a/cmd/dagger/cmd/project/projectroot.go +++ b/cmd/dagger/cmd/project/projectroot.go @@ -26,5 +26,6 @@ func init() { Cmd.AddCommand( initCmd, updateCmd, + infoCmd, ) } diff --git a/tests/project.bats b/tests/project.bats index 65574fe3..50b09787 100644 --- a/tests/project.bats +++ b/tests/project.bats @@ -2,11 +2,11 @@ setup() { load 'helpers' common_setup - + TEMPDIR=$(mktemp -d) } -@test "project init and update" { +@test "project init and update and info" { cd "$TEMPDIR" || exit "$DAGGER" project init ./ --name "github.com/foo/bar" @@ -27,4 +27,8 @@ setup() { assert_output --partial "generated by dagger" test ! -f ./cue.mod/pkg/.gitignore + + + "$DAGGER" project info + assert_output --partial "Current dagger project in" } From 5759071bd7214619a8d6f14ba1b542ad7ff4fdf1 Mon Sep 17 00:00:00 2001 From: Kenneth Lear Date: Wed, 6 Apr 2022 21:26:38 -0400 Subject: [PATCH 2/5] test: Update project info command to pass lint and test to make sure TEMPDIR is there Signed-off-by: Kenneth Lear --- cmd/dagger/cmd/project/info.go | 3 ++- tests/project.bats | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/dagger/cmd/project/info.go b/cmd/dagger/cmd/project/info.go index c536fb5f..7fd1edb6 100644 --- a/cmd/dagger/cmd/project/info.go +++ b/cmd/dagger/cmd/project/info.go @@ -2,6 +2,7 @@ package project import ( "fmt" + "github.com/spf13/cobra" "github.com/spf13/viper" "go.dagger.io/dagger/cmd/dagger/logger" @@ -27,7 +28,7 @@ var infoCmd = &cobra.Command{ lg.Fatal().Msg("dagger project not found. Run `dagger project init`") } - fmt.Println(fmt.Sprintf("Current dagger project in: %s", cueModPath)) + fmt.Printf("\nCurrent dagger project in: %s", cueModPath) // TODO: find available plans and if they load successfully }, diff --git a/tests/project.bats b/tests/project.bats index 50b09787..8df55dcc 100644 --- a/tests/project.bats +++ b/tests/project.bats @@ -31,4 +31,5 @@ setup() { "$DAGGER" project info assert_output --partial "Current dagger project in" + assert_output --partial "$TEMPDIR" } From ed236d4934c7c8d4b450e6c5687ab1e306f58eae Mon Sep 17 00:00:00 2001 From: Kenneth Lear Date: Wed, 6 Apr 2022 21:47:46 -0400 Subject: [PATCH 3/5] test: Fixing project info integration test Signed-off-by: Kenneth Lear --- tests/project.bats | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/project.bats b/tests/project.bats index 8df55dcc..013a4b9c 100644 --- a/tests/project.bats +++ b/tests/project.bats @@ -28,8 +28,7 @@ setup() { test ! -f ./cue.mod/pkg/.gitignore - "$DAGGER" project info - assert_output --partial "Current dagger project in" + assert_output --partial "Current dagger project in:" assert_output --partial "$TEMPDIR" } From abe1e36032cfd7a78283304f17494d8bb9402723 Mon Sep 17 00:00:00 2001 From: Kenneth Lear Date: Wed, 6 Apr 2022 22:56:56 -0400 Subject: [PATCH 4/5] test: Update project info test to fix issue Signed-off-by: Kenneth Lear --- tests/project.bats | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/project.bats b/tests/project.bats index 013a4b9c..0920f107 100644 --- a/tests/project.bats +++ b/tests/project.bats @@ -28,7 +28,8 @@ setup() { test ! -f ./cue.mod/pkg/.gitignore - "$DAGGER" project info + run "$DAGGER" project info + assert_success assert_output --partial "Current dagger project in:" assert_output --partial "$TEMPDIR" } From 7cf8c280af569f635637e918f14e24eda31dba2c Mon Sep 17 00:00:00 2001 From: teddylear Date: Thu, 7 Apr 2022 17:16:51 -0400 Subject: [PATCH 5/5] tests: Adding update to project info for negative test case Signed-off-by: teddylear --- cmd/dagger/cmd/project/info.go | 2 +- tests/project.bats | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/dagger/cmd/project/info.go b/cmd/dagger/cmd/project/info.go index 7fd1edb6..e930f3fa 100644 --- a/cmd/dagger/cmd/project/info.go +++ b/cmd/dagger/cmd/project/info.go @@ -28,7 +28,7 @@ var infoCmd = &cobra.Command{ lg.Fatal().Msg("dagger project not found. Run `dagger project init`") } - fmt.Printf("\nCurrent dagger project in: %s", cueModPath) + fmt.Printf("\nCurrent dagger project in: %s\n", cueModPath) // TODO: find available plans and if they load successfully }, diff --git a/tests/project.bats b/tests/project.bats index 0920f107..45382abc 100644 --- a/tests/project.bats +++ b/tests/project.bats @@ -4,6 +4,7 @@ setup() { common_setup TEMPDIR=$(mktemp -d) + TEMPDIR2=$(mktemp -d) } @test "project init and update and info" { @@ -32,4 +33,9 @@ setup() { 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\`" }