RunRun executes the functionality "devspace run"
(f factory.Factory, args []string)
| 91 | |
| 92 | // RunRun executes the functionality "devspace run" |
| 93 | func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error { |
| 94 | if len(args) == 0 { |
| 95 | return fmt.Errorf("run requires at least one argument") |
| 96 | } |
| 97 | |
| 98 | // check if dependency command |
| 99 | commandSplitted := strings.Split(args[0], ".") |
| 100 | if len(commandSplitted) > 1 { |
| 101 | cmd.Dependency = strings.Join(commandSplitted[:len(commandSplitted)-1], ".") |
| 102 | args[0] = commandSplitted[len(commandSplitted)-1] |
| 103 | } |
| 104 | |
| 105 | // Execute plugin hook |
| 106 | err := hook.ExecuteHooks(nil, nil, "run") |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | // Set config root |
| 112 | configOptions := cmd.ToConfigOptions() |
| 113 | configLoader, err := f.NewConfigLoader(cmd.ConfigPath) |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | configExists, err := configLoader.SetDevSpaceRoot(f.GetLog()) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } else if !configExists { |
| 121 | return errors.New(message.ConfigNotFound) |
| 122 | } |
| 123 | |
| 124 | // load the config |
| 125 | ctx, err := cmd.LoadCommandsConfig(f, configLoader, configOptions, f.GetLog()) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | |
| 130 | // check if we should execute a dependency command |
| 131 | if cmd.Dependency != "" { |
| 132 | config, err := configLoader.LoadWithCache(context.Background(), ctx.Config().LocalCache(), nil, configOptions, f.GetLog()) |
| 133 | if err != nil { |
| 134 | return err |
| 135 | } |
| 136 | |
| 137 | ctx = ctx.WithConfig(config) |
| 138 | dependencies, err := f.NewDependencyManager(ctx, configOptions).ResolveAll(ctx, dependency.ResolveOptions{}) |
| 139 | if err != nil { |
| 140 | return err |
| 141 | } |
| 142 | |
| 143 | dep := dependency.GetDependencyByPath(dependencies, cmd.Dependency) |
| 144 | if dep == nil { |
| 145 | return fmt.Errorf("couldn't find dependency %s", cmd.Dependency) |
| 146 | } |
| 147 | |
| 148 | ctx = ctx.AsDependency(dep) |
| 149 | commandConfig, err := findCommand(ctx.Config(), args[0]) |
| 150 | if err != nil { |
no test coverage detected