@@ -10,7 +10,9 @@ import (
1010
1111 "github.com/drycc/workflow-cli/internal/commands"
1212 "github.com/drycc/workflow-cli/internal/parser"
13+ "github.com/drycc/workflow-cli/internal/plugins"
1314 "github.com/drycc/workflow-cli/pkg/i18n"
15+ "github.com/drycc/workflow-cli/pkg/settings"
1416 "github.com/spf13/cobra"
1517)
1618
@@ -57,9 +59,9 @@ func NewDryccCommand() *cobra.Command {
5759 rootCmd .AddCommand (parser .NewWorkspacesCommand (& cmdr ))
5860 rootCmd .AddCommand (parser .NewPsCommand (& cmdr ))
5961 rootCmd .AddCommand (parser .NewPtsCommand (& cmdr ))
62+ rootCmd .AddCommand (parser .NewPluginsCommand (& cmdr ))
6063 rootCmd .AddCommand (parser .NewRegistryCommand (& cmdr ))
6164 rootCmd .AddCommand (parser .NewReleasesCommand (& cmdr ))
62- rootCmd .AddCommand (parser .NewResourcesCommand (& cmdr ))
6365 rootCmd .AddCommand (parser .NewRoutesCommand (& cmdr ))
6466 rootCmd .AddCommand (parser .NewRoutingCommand (& cmdr ))
6567 rootCmd .AddCommand (parser .NewServicesCommand (& cmdr ))
@@ -82,3 +84,45 @@ func NewDryccCommand() *cobra.Command {
8284
8385 return rootCmd
8486}
87+
88+ // ExecuteWithPlugins runs the root command with plugin dispatch support
89+ func ExecuteWithPlugins (rootCmd * cobra.Command , config string ) error {
90+ // Try to find the command first
91+ cmd , _ , err := rootCmd .Find (os .Args [1 :])
92+ if err != nil || cmd == rootCmd {
93+ // Command not found or is root command, try plugin dispatch
94+ name := firstNonFlagArg (os .Args [1 :])
95+ if name != "" {
96+ if path , ok := plugins .LookupPlugin (name ); ok {
97+ restArgs := argsAfter (os .Args [1 :], name )
98+ s , serr := settings .Load (config )
99+ if serr != nil {
100+ // If settings can't be loaded, use empty settings
101+ s = & settings.Settings {}
102+ }
103+ return plugins .Run (path , restArgs , s )
104+ }
105+ }
106+ }
107+ return rootCmd .Execute ()
108+ }
109+
110+ // firstNonFlagArg returns the first argument that doesn't start with "-"
111+ func firstNonFlagArg (args []string ) string {
112+ for _ , arg := range args {
113+ if len (arg ) > 0 && arg [0 ] != '-' {
114+ return arg
115+ }
116+ }
117+ return ""
118+ }
119+
120+ // argsAfter returns all arguments after the specified name
121+ func argsAfter (args []string , name string ) []string {
122+ for i , arg := range args {
123+ if arg == name {
124+ return args [i + 1 :]
125+ }
126+ }
127+ return args
128+ }
0 commit comments