Merge pull request #1690 from talentedmrjones/dagger-do-plan-flag

dagger do now uses --plan instead of --project
This commit is contained in:
Andrea Luzzardi 2022-03-07 12:11:37 -08:00 committed by GitHub
commit cbd3dbf45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"path/filepath"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
@ -77,9 +78,22 @@ var doCmd = &cobra.Command{
} }
func loadPlan(target string) (*plan.Plan, error) { func loadPlan(target string) (*plan.Plan, error) {
project := viper.GetString("project") planPath := viper.GetString("plan")
// support only local filesystem paths
// even though CUE supports loading module and package names
absPlanPath, err := filepath.Abs(planPath)
if err != nil {
return nil, err
}
_, err = os.Stat(absPlanPath)
if err != nil {
return nil, err
}
return plan.Load(context.Background(), plan.Config{ return plan.Load(context.Background(), plan.Config{
Args: []string{project}, Args: []string{planPath},
With: viper.GetStringSlice("with"), With: viper.GetStringSlice("with"),
Target: target, Target: target,
Vendor: !viper.GetBool("no-vendor"), Vendor: !viper.GetBool("no-vendor"),
@ -106,7 +120,7 @@ func doHelp(cmd *cobra.Command, _ []string) {
fmt.Fprintln(w, "failed to load plan") fmt.Fprintln(w, "failed to load plan")
return return
} }
project := viper.GetString("project") planPath := viper.GetString("plan")
actionLookupPath := getTargetPath(cmd.Flags().Args()) actionLookupPath := getTargetPath(cmd.Flags().Args())
actions := p.Action().FindByPath(actionLookupPath).Children actions := p.Action().FindByPath(actionLookupPath).Children
@ -116,7 +130,7 @@ func doHelp(cmd *cobra.Command, _ []string) {
Plan loaded from %s: Plan loaded from %s:
%s %s
`, cmd.UsageString(), project, "\n"+actionLookupPath.String()+":") `, cmd.UsageString(), planPath, "\n"+actionLookupPath.String()+":")
// fmt.Fprintln(w, "Actions\tDescription\tPackage") // fmt.Fprintln(w, "Actions\tDescription\tPackage")
// fmt.Fprintln(w, "\t\t") // fmt.Fprintln(w, "\t\t")
@ -131,6 +145,7 @@ Plan loaded from %s:
func init() { func init() {
doCmd.Flags().StringArrayP("with", "w", []string{}, "") doCmd.Flags().StringArrayP("with", "w", []string{}, "")
doCmd.Flags().Bool("no-vendor", false, "Force up, disable inputs check") doCmd.Flags().Bool("no-vendor", false, "Force up, disable inputs check")
doCmd.PersistentFlags().StringP("plan", "p", ".", "Path to plan (defaults to current directory)")
doCmd.SetHelpFunc(doHelp) doCmd.SetHelpFunc(doHelp)

View File

@ -31,8 +31,6 @@ func init() {
rootCmd.PersistentFlags().StringArray("cache-from", []string{}, rootCmd.PersistentFlags().StringArray("cache-from", []string{},
"External cache sources (eg. user/app:cache, type=local,src=path/to/dir)") "External cache sources (eg. user/app:cache, type=local,src=path/to/dir)")
rootCmd.PersistentFlags().StringP("project", "p", "./", "Specify a project directory (defaults to current)")
rootCmd.PersistentPreRun = func(cmd *cobra.Command, _ []string) { rootCmd.PersistentPreRun = func(cmd *cobra.Command, _ []string) {
go checkVersion() go checkVersion()
} }