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" }