diff --git a/cmd/dagger/cmd/do.go b/cmd/dagger/cmd/do.go index 1f370366..2d7e5e3d 100644 --- a/cmd/dagger/cmd/do.go +++ b/cmd/dagger/cmd/do.go @@ -88,9 +88,8 @@ func loadPlan() (*plan.Plan, error) { } return plan.Load(context.Background(), plan.Config{ - Args: []string{planPath}, - With: viper.GetStringSlice("with"), - Vendor: !viper.GetBool("no-vendor"), + Args: []string{planPath}, + With: viper.GetStringSlice("with"), }) } @@ -106,23 +105,32 @@ func doHelp(cmd *cobra.Command, _ []string) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.StripEscape) defer w.Flush() + planPath := viper.GetString("plan") + + var ( + errorMsg string + loadedMsg string + actionLookupPathMsg string + actions []*plan.Action + ) + p, err := loadPlan() if err != nil { - fmt.Printf("%s", err) - fmt.Fprintln(w, "failed to load plan") - return + errorMsg = "Error: failed to load plan\n\n" + } else { + loadedMsg = "Plan loaded from " + planPath + actionLookupPath := getTargetPath(cmd.Flags().Args()) + actions = p.Action().FindByPath(actionLookupPath).Children + actionLookupPathMsg = fmt.Sprintf(`%s:`, actionLookupPath.String()) } - planPath := viper.GetString("plan") - actionLookupPath := getTargetPath(cmd.Flags().Args()) - actions := p.Action().FindByPath(actionLookupPath).Children - - fmt.Printf(`Execute a dagger action. + fmt.Printf(`%s%s %s -Plan loaded from %s: %s -`, cmd.UsageString(), planPath, "\n"+actionLookupPath.String()+":") + +%s +`, errorMsg, cmd.Short, cmd.UsageString(), loadedMsg, actionLookupPathMsg) // fmt.Fprintln(w, "Actions\tDescription\tPackage") // fmt.Fprintln(w, "\t\t") @@ -136,8 +144,7 @@ Plan loaded from %s: func init() { doCmd.Flags().StringArrayP("with", "w", []string{}, "") - doCmd.Flags().Bool("no-vendor", false, "Force up, disable inputs check") - doCmd.PersistentFlags().StringP("plan", "p", ".", "Path to plan (defaults to current directory)") + doCmd.Flags().StringP("plan", "p", ".", "Path to plan (defaults to current directory)") doCmd.SetHelpFunc(doHelp) diff --git a/cmd/dagger/cmd/mod/root.go b/cmd/dagger/cmd/mod/root.go deleted file mode 100644 index 87d934ab..00000000 --- a/cmd/dagger/cmd/mod/root.go +++ /dev/null @@ -1,15 +0,0 @@ -package mod - -import "github.com/spf13/cobra" - -// Cmd exposes the top-level command -var Cmd = &cobra.Command{ - Use: "mod", - Short: "Manage an environment's dependencies", -} - -func init() { - Cmd.AddCommand( - getCmd, - ) -} diff --git a/cmd/dagger/cmd/project/init.go b/cmd/dagger/cmd/project/init.go index ce3b261f..862cf606 100644 --- a/cmd/dagger/cmd/project/init.go +++ b/cmd/dagger/cmd/project/init.go @@ -14,7 +14,7 @@ var sep = string(os.PathSeparator) var initCmd = &cobra.Command{ Use: fmt.Sprintf("init [path%sto%sproject]", sep, sep), - Short: "Initialize a new empty project.", + Short: "Initialize a new empty project", Args: cobra.MaximumNArgs(1), PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: diff --git a/cmd/dagger/cmd/project/root.go b/cmd/dagger/cmd/project/projectroot.go similarity index 97% rename from cmd/dagger/cmd/project/root.go rename to cmd/dagger/cmd/project/projectroot.go index 733fe173..386ebe0a 100644 --- a/cmd/dagger/cmd/project/root.go +++ b/cmd/dagger/cmd/project/projectroot.go @@ -25,5 +25,6 @@ func init() { Cmd.AddCommand( initCmd, + updateCmd, ) } diff --git a/cmd/dagger/cmd/mod/get.go b/cmd/dagger/cmd/project/update.go similarity index 67% rename from cmd/dagger/cmd/mod/get.go rename to cmd/dagger/cmd/project/update.go index e668c918..e1f97e9b 100644 --- a/cmd/dagger/cmd/mod/get.go +++ b/cmd/dagger/cmd/project/update.go @@ -1,4 +1,4 @@ -package mod +package project import ( "github.com/spf13/cobra" @@ -8,9 +8,9 @@ import ( "go.dagger.io/dagger/pkg" ) -var getCmd = &cobra.Command{ - Use: "get [packages]", - Short: "download and install dependencies", +var updateCmd = &cobra.Command{ + Use: "update [package]", + Short: "Download and install dependencies", Args: cobra.MaximumNArgs(1), PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: @@ -26,11 +26,15 @@ var getCmd = &cobra.Command{ var err error - cueModPath := pkg.GetCueModParent() - err = pkg.CueModInit(ctx, cueModPath, "") - if err != nil { - lg.Fatal().Err(err).Msg("failed to initialize cue.mod") - panic(err) + cueModPath, cueModExists := pkg.GetCueModParent() + if !cueModExists { + lg.Fatal().Msg("dagger project not found. Run `dagger project init`") + } + + if len(args) == 0 { + lg.Debug().Msg("No package specified, updating all packages") + pkg.Vendor(ctx, cueModPath) + return } var update = viper.GetBool("update") @@ -64,11 +68,11 @@ var getCmd = &cobra.Command{ } func init() { - getCmd.Flags().String("private-key-file", "", "Private ssh key") - getCmd.Flags().String("private-key-password", "", "Private ssh key password") - getCmd.Flags().BoolP("update", "u", false, "Update specified package") + updateCmd.Flags().String("private-key-file", "", "Private ssh key") + updateCmd.Flags().String("private-key-password", "", "Private ssh key password") + updateCmd.Flags().BoolP("update", "u", false, "Update specified package") - if err := viper.BindPFlags(getCmd.Flags()); err != nil { + if err := viper.BindPFlags(updateCmd.Flags()); err != nil { panic(err) } } diff --git a/cmd/dagger/cmd/root.go b/cmd/dagger/cmd/root.go index 4d8fb161..3f0e03fb 100644 --- a/cmd/dagger/cmd/root.go +++ b/cmd/dagger/cmd/root.go @@ -7,7 +7,6 @@ import ( "github.com/moby/buildkit/util/appcontext" "github.com/spf13/cobra" "github.com/spf13/viper" - "go.dagger.io/dagger/cmd/dagger/cmd/mod" "go.dagger.io/dagger/cmd/dagger/cmd/project" "go.dagger.io/dagger/cmd/dagger/logger" @@ -42,7 +41,6 @@ func init() { upCmd, versionCmd, docCmd, - mod.Cmd, doCmd, project.Cmd, ) diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 82b3c2b9..6297189a 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -82,7 +82,6 @@ func europaUp(ctx context.Context, cl *client.Client, args ...string) error { Args: args, With: viper.GetStringSlice("with"), Target: viper.GetString("target"), - Vendor: !viper.GetBool("no-vendor"), }) if err != nil { lg.Fatal().Err(err).Msg("failed to load plan") @@ -97,7 +96,6 @@ func init() { upCmd.Flags().BoolP("force", "f", false, "Force up, disable inputs check") upCmd.Flags().StringArrayP("with", "w", []string{}, "") upCmd.Flags().StringP("target", "t", "", "Run a single target of the DAG (for debugging only)") - upCmd.Flags().Bool("no-vendor", false, "Force up, disable inputs check") if err := viper.BindPFlags(upCmd.Flags()); err != nil { panic(err) diff --git a/pkg/pkg.go b/pkg/pkg.go index 9385871e..f5680a48 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -37,7 +37,7 @@ var ( func Vendor(ctx context.Context, p string) error { if p == "" { - p = GetCueModParent() + p, _ = GetCueModParent() } cuePkgDir := path.Join(p, "cue.mod", "pkg") @@ -144,12 +144,14 @@ func extractModules(dest string) error { } // GetCueModParent traverses the directory tree up through ancestors looking for a cue.mod folder -func GetCueModParent() string { +func GetCueModParent() (string, bool) { cwd, _ := os.Getwd() parentDir := cwd + found := false for { if _, err := os.Stat(path.Join(parentDir, "cue.mod")); !errors.Is(err, os.ErrNotExist) { + found = true break // found it! } @@ -162,7 +164,7 @@ func GetCueModParent() string { } } - return parentDir + return parentDir, found } func CueModInit(ctx context.Context, parentDir, module string) error { diff --git a/pkg/universe.dagger.io/cue.mod/pkg/.gitignore b/pkg/universe.dagger.io/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/pkg/universe.dagger.io/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/pkg/universe.dagger.io/cue.mod/pkg/dagger.io b/pkg/universe.dagger.io/cue.mod/pkg/dagger.io new file mode 120000 index 00000000..cb095939 --- /dev/null +++ b/pkg/universe.dagger.io/cue.mod/pkg/dagger.io @@ -0,0 +1 @@ +../../../dagger.io \ No newline at end of file diff --git a/plan/plan.go b/plan/plan.go index 2b5c7702..6090554c 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -32,18 +32,14 @@ type Config struct { Args []string With []string Target string - Vendor bool } func Load(ctx context.Context, cfg Config) (*Plan, error) { log.Ctx(ctx).Debug().Interface("args", cfg.Args).Msg("loading plan") - // FIXME: move vendoring to explicit project update command - if cfg.Vendor { - // FIXME: vendoring path - if err := pkg.Vendor(ctx, ""); err != nil { - return nil, err - } + _, cueModExists := pkg.GetCueModParent() + if !cueModExists { + return nil, fmt.Errorf("dagger project not found. Run `dagger project init`") } v, err := compiler.Build("", nil, cfg.Args...) diff --git a/tests/cue.mod/pkg/.gitignore b/tests/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/cue.mod/pkg/dagger.io b/tests/cue.mod/pkg/dagger.io new file mode 120000 index 00000000..61c69ed9 --- /dev/null +++ b/tests/cue.mod/pkg/dagger.io @@ -0,0 +1 @@ +../../../pkg/dagger.io \ No newline at end of file diff --git a/tests/cue.mod/pkg/universe.dagger.io b/tests/cue.mod/pkg/universe.dagger.io new file mode 120000 index 00000000..9b1eece6 --- /dev/null +++ b/tests/cue.mod/pkg/universe.dagger.io @@ -0,0 +1 @@ +../../../pkg/universe.dagger.io \ No newline at end of file diff --git a/tests/plan/platform/cue.mod/module.cue b/tests/plan/platform/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/plan/platform/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/plan/platform/cue.mod/pkg/.gitignore b/tests/plan/platform/cue.mod/pkg/.gitignore deleted file mode 100644 index a72db682..00000000 --- a/tests/plan/platform/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.io -universe.dagger.io -dagger.lock diff --git a/tests/project.bats b/tests/project.bats index cb62cd1d..4b8b409a 100644 --- a/tests/project.bats +++ b/tests/project.bats @@ -4,13 +4,19 @@ setup() { common_setup } -@test "project init" { - cd "$TESTDIR" - # mkdir -p ./project/init - "$DAGGER" project init ./project/init --name "github.com/foo/bar" - test -d ./project/init/cue.mod/pkg - test -d ./project/init/cue.mod/usr - test -f ./project/init/cue.mod/module.cue - contents=$(cat ./project/init/cue.mod/module.cue) +@test "project init and update" { + TEMPDIR=$(mktemp -d) + echo "TEMPDIR=$TEMPDIR" + cd "$TEMPDIR" + + "$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"' ] -} \ No newline at end of file + + dagger project update + test -d ./cue.mod/pkg/dagger.io + test -d ./cue.mod/pkg/universe.dagger.io +} diff --git a/tests/tasks/build/cue.mod/pkg/.gitignore b/tests/tasks/build/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/build/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/copy/cue.mod/module.cue b/tests/tasks/copy/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/copy/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/copy/cue.mod/pkg/.gitignore b/tests/tasks/copy/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/copy/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/dockerfile/cue.mod/module.cue b/tests/tasks/dockerfile/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/dockerfile/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/dockerfile/cue.mod/pkg/.gitignore b/tests/tasks/dockerfile/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/dockerfile/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/exec/cue.mod/module.cue b/tests/tasks/exec/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/exec/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/exec/cue.mod/pkg/.gitignore b/tests/tasks/exec/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/exec/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/hidden/cue.mod/module.cue b/tests/tasks/hidden/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/hidden/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/hidden/cue.mod/pkg/.gitignore b/tests/tasks/hidden/cue.mod/pkg/.gitignore deleted file mode 100644 index ec3af5b0..00000000 --- a/tests/tasks/hidden/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# generated by dagger -dagger.io -dagger.lock diff --git a/tests/tasks/hidden/cue.mod/usr/testing.dagger.io/hidden/hidden.cue b/tests/tasks/hidden/cue.mod/usr/testing.dagger.io/hidden/hidden.cue deleted file mode 100644 index 454bcea0..00000000 --- a/tests/tasks/hidden/cue.mod/usr/testing.dagger.io/hidden/hidden.cue +++ /dev/null @@ -1,25 +0,0 @@ -package hidden - -import ( -) - -#Hidden: { - _pull: dagger.#Pull & { - source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3" - } - _write: dagger.#WriteFile & { - input: _pull.output - path: "/testing" - contents: "1,2,3" - permissions: 700 - } - _readfile: dagger.#ReadFile & { - input: _write.output - path: "/testing" - } & { - // assert result - contents: "1,2,3" - } - output: _write.output - contents: _readfile.contents -} diff --git a/tests/tasks/mkdir/cue.mod/module.cue b/tests/tasks/mkdir/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/mkdir/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/mkdir/cue.mod/pkg/.gitignore b/tests/tasks/mkdir/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/mkdir/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/pull/cue.mod/module.cue b/tests/tasks/pull/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/pull/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/pull/cue.mod/pkg/.gitignore b/tests/tasks/pull/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/pull/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/push/cue.mod/module.cue b/tests/tasks/push/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/push/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/push/cue.mod/pkg/.gitignore b/tests/tasks/push/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/push/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/readfile/cue.mod/module.cue b/tests/tasks/readfile/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/readfile/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/readfile/cue.mod/pkg/.gitignore b/tests/tasks/readfile/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/readfile/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/scratch/cue.mod/module.cue b/tests/tasks/scratch/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/scratch/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/scratch/cue.mod/pkg/.gitignore b/tests/tasks/scratch/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/scratch/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/writefile/cue.mod/module.cue b/tests/tasks/writefile/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/tasks/writefile/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/tasks/writefile/cue.mod/pkg/.gitignore b/tests/tasks/writefile/cue.mod/pkg/.gitignore deleted file mode 100644 index 8e3152ec..00000000 --- a/tests/tasks/writefile/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# generated by dagger -dagger.lock -dagger.io -universe.dagger.io \ No newline at end of file