Merge pull request #2062 from teddylear/project-info-cmd
feat: Adding project info command to find where project is located
This commit is contained in:
commit
caf6e5896d
35
cmd/dagger/cmd/project/info.go
Normal file
35
cmd/dagger/cmd/project/info.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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.Printf("\nCurrent dagger project in: %s\n", cueModPath)
|
||||||
|
|
||||||
|
// TODO: find available plans and if they load successfully
|
||||||
|
},
|
||||||
|
}
|
@ -26,5 +26,6 @@ func init() {
|
|||||||
Cmd.AddCommand(
|
Cmd.AddCommand(
|
||||||
initCmd,
|
initCmd,
|
||||||
updateCmd,
|
updateCmd,
|
||||||
|
infoCmd,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@ setup() {
|
|||||||
common_setup
|
common_setup
|
||||||
|
|
||||||
TEMPDIR=$(mktemp -d)
|
TEMPDIR=$(mktemp -d)
|
||||||
|
TEMPDIR2=$(mktemp -d)
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "project init and update" {
|
@test "project init and update and info" {
|
||||||
cd "$TEMPDIR" || exit
|
cd "$TEMPDIR" || exit
|
||||||
|
|
||||||
"$DAGGER" project init ./ --name "github.com/foo/bar"
|
"$DAGGER" project init ./ --name "github.com/foo/bar"
|
||||||
@ -27,4 +28,14 @@ setup() {
|
|||||||
assert_output --partial "generated by dagger"
|
assert_output --partial "generated by dagger"
|
||||||
|
|
||||||
test ! -f ./cue.mod/pkg/.gitignore
|
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\`"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user