@@ -5,25 +5,23 @@ import (
55 "fmt"
66 "github.com/loft-sh/devspace/pkg/devspace/config"
77 devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8+ "github.com/loft-sh/devspace/pkg/devspace/hook"
89 "github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
910 "github.com/loft-sh/devspace/pkg/util/command"
1011 "github.com/loft-sh/devspace/pkg/util/exit"
12+ "github.com/loft-sh/devspace/pkg/util/log"
1113 "io"
1214 "mvdan.cc/sh/v3/interp"
1315 "os"
1416 "strings"
1517
16- "github.com/loft-sh/devspace/pkg/devspace/hook"
17-
1818 "github.com/loft-sh/devspace/pkg/devspace/config/loader"
19- "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
2019 "github.com/loft-sh/devspace/pkg/devspace/plugin"
2120
2221 "github.com/loft-sh/devspace/cmd/flags"
2322 "github.com/loft-sh/devspace/pkg/devspace/dependency"
2423 "github.com/loft-sh/devspace/pkg/util/factory"
2524 flagspkg "github.com/loft-sh/devspace/pkg/util/flags"
26- "github.com/loft-sh/devspace/pkg/util/log"
2725 "github.com/loft-sh/devspace/pkg/util/message"
2826 "github.com/sirupsen/logrus"
2927
@@ -41,7 +39,7 @@ type RunCmd struct {
4139}
4240
4341// NewRunCmd creates a new run command
44- func NewRunCmd (f factory.Factory , globalFlags * flags.GlobalFlags ) * cobra.Command {
42+ func NewRunCmd (f factory.Factory , globalFlags * flags.GlobalFlags , rawConfig * RawConfig ) * cobra.Command {
4543 cmd := & RunCmd {
4644 GlobalFlags : globalFlags ,
4745 Stdout : os .Stdout ,
@@ -103,29 +101,32 @@ devspace --dependency my-dependency run any-command --any-command-flag
103101 },
104102 }
105103
106- commands , _ := getCommands (f )
107- for _ , command := range commands {
108- description := command .Description
109- if description == "" {
110- description = "Runs command: " + command .Command
111- }
112- if len (description ) > 64 {
113- if len (description ) > 64 {
114- description = description [:61 ] + "..."
104+ if rawConfig != nil {
105+ latest , _ , _ := loader .NewCommandsParser ().Parse (rawConfig .Ctx , rawConfig .OriginalRawConfig , rawConfig .RawConfig , rawConfig .Resolver , log .Discard )
106+ if latest != nil {
107+ for _ , cmd := range latest .Commands {
108+ description := cmd .Description
109+ if description == "" {
110+ description = "Runs command: " + cmd .Command
111+ }
112+ if len (description ) > 64 {
113+ if len (description ) > 64 {
114+ description = description [:61 ] + "..."
115+ }
116+ }
117+ runCmd .AddCommand (& cobra.Command {
118+ Use : cmd .Name ,
119+ Short : description ,
120+ Long : description ,
121+ Args : cobra .ArbitraryArgs ,
122+ DisableFlagParsing : true ,
123+ RunE : func (cobraCmd * cobra.Command , args []string ) error {
124+ return cobraCmd .Parent ().RunE (cobraCmd , args )
125+ },
126+ })
115127 }
116128 }
117- runCmd .AddCommand (& cobra.Command {
118- Use : command .Name ,
119- Short : description ,
120- Long : description ,
121- Args : cobra .ArbitraryArgs ,
122- DisableFlagParsing : true ,
123- RunE : func (cobraCmd * cobra.Command , args []string ) error {
124- return cobraCmd .Parent ().RunE (cobraCmd , args )
125- },
126- })
127129 }
128-
129130 runCmd .Flags ().StringVar (& cmd .Dependency , "dependency" , "" , "Run a command from a specific dependency" )
130131 return runCmd
131132}
@@ -256,34 +257,3 @@ func ExecuteConfigCommand(ctx context.Context, config config.Config, name string
256257 shellArgs = append (shellArgs , args ... )
257258 return command .CommandWithEnv (ctx , dir , stdout , stderr , stdin , extraEnv , shellCommand , shellArgs ... )
258259}
259-
260- func getCommands (f factory.Factory ) (map [string ]* latest.CommandConfig , error ) {
261- // get current working dir
262- cwd , err := os .Getwd ()
263- if err != nil {
264- return nil , err
265- }
266-
267- // set working dir back to original
268- defer func () { _ = os .Chdir (cwd ) }()
269-
270- // Set config root
271- configLoader , err := f .NewConfigLoader ("" )
272- if err != nil {
273- return nil , err
274- }
275- configExists , err := configLoader .SetDevSpaceRoot (log .Discard )
276- if err != nil {
277- return nil , err
278- }
279- if ! configExists {
280- return nil , errors .New (message .ConfigNotFound )
281- }
282-
283- // Parse commands
284- commandsInterface , err := configLoader .LoadWithParser (context .Background (), nil , nil , loader .NewCommandsParser (), & loader.ConfigOptions {Dry : true }, log .Discard )
285- if err != nil {
286- return nil , err
287- }
288- return commandsInterface .Config ().Commands , nil
289- }
0 commit comments