@@ -2,18 +2,21 @@ package cmd
22
33import (
44 "fmt"
5- "github.com/loft-sh/devspace/pkg/devspace/hook"
65 "io"
76 "os"
87 "strings"
98
9+ "github.com/loft-sh/devspace/pkg/devspace/hook"
10+
1011 "github.com/loft-sh/devspace/pkg/devspace/config/loader"
12+ "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
1113 "github.com/loft-sh/devspace/pkg/devspace/plugin"
1214
1315 "github.com/loft-sh/devspace/cmd/flags"
1416 "github.com/loft-sh/devspace/pkg/devspace/dependency"
1517 "github.com/loft-sh/devspace/pkg/util/factory"
1618 flagspkg "github.com/loft-sh/devspace/pkg/util/flags"
19+ "github.com/loft-sh/devspace/pkg/util/log"
1720 "github.com/loft-sh/devspace/pkg/util/message"
1821 "github.com/sirupsen/logrus"
1922
@@ -93,6 +96,30 @@ devspace --dependency my-dependency run any-command --any-command-flag
9396 },
9497 }
9598
99+ logger := f .GetLog ()
100+ commands , _ := getCommands (f , logger )
101+ for _ , command := range commands {
102+ description := command .Description
103+ if description == "" {
104+ description = "Runs command: " + command .Command
105+ }
106+ if len (description ) > 64 {
107+ if len (description ) > 64 {
108+ description = description [:61 ] + "..."
109+ }
110+ }
111+ runCmd .AddCommand (& cobra.Command {
112+ Use : command .Name ,
113+ Short : description ,
114+ Long : description ,
115+ Args : cobra .ArbitraryArgs ,
116+ DisableFlagParsing : true ,
117+ RunE : func (cobraCmd * cobra.Command , args []string ) error {
118+ return cobraCmd .Parent ().RunE (cobraCmd , args )
119+ },
120+ })
121+ }
122+
96123 runCmd .Flags ().StringVar (& cmd .Dependency , "dependency" , "" , "Run a command from a specific dependency" )
97124 return runCmd
98125}
@@ -164,3 +191,22 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
164191 // Execute command
165192 return dependency .ExecuteCommand (commands , args [0 ], args [1 :], cmd .Stdout , cmd .Stderr )
166193}
194+
195+ func getCommands (f factory.Factory , logger log.Logger ) ([]* latest.CommandConfig , error ) {
196+ // Set config root
197+ configLoader := f .NewConfigLoader ("" )
198+ configExists , err := configLoader .SetDevSpaceRoot (logger )
199+ if err != nil {
200+ return nil , err
201+ }
202+ if ! configExists {
203+ return nil , errors .New (message .ConfigNotFound )
204+ }
205+
206+ // Parse commands
207+ commandsInterface , err := configLoader .LoadWithParser (loader .NewCommandsParser (), nil , logger )
208+ if err != nil {
209+ return nil , err
210+ }
211+ return commandsInterface .Config ().Commands , nil
212+ }
0 commit comments