Run executes the command logic
(f factory.Factory)
| 69 | |
| 70 | // Run executes the command logic |
| 71 | func (cmd *PrintCmd) Run(f factory.Factory) error { |
| 72 | // Set config root |
| 73 | log := f.GetLog() |
| 74 | configOptions := cmd.ToConfigOptions() |
| 75 | configLoader, err := f.NewConfigLoader(cmd.ConfigPath) |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | configExists, err := configLoader.SetDevSpaceRoot(log) |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } else if !configExists { |
| 83 | return errors.New(message.ConfigNotFound) |
| 84 | } |
| 85 | |
| 86 | // create kubectl client |
| 87 | client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace) |
| 88 | if err != nil { |
| 89 | log.Warnf("Unable to create new kubectl client: %v", err) |
| 90 | } |
| 91 | |
| 92 | parser := loader.NewEagerParser() |
| 93 | |
| 94 | // load config |
| 95 | config, err := configLoader.LoadWithParser(context.Background(), nil, client, parser, configOptions, log) |
| 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | |
| 100 | // create devspace context |
| 101 | ctx := devspacecontext.NewContext(context.Background(), config.Variables(), log). |
| 102 | WithConfig(config). |
| 103 | WithKubeClient(client) |
| 104 | |
| 105 | // resolve dependencies |
| 106 | dependencies, err := dependency.NewManagerWithParser(ctx, configOptions, parser).ResolveAll(ctx, dependency.ResolveOptions{}) |
| 107 | if err != nil { |
| 108 | log.Warnf("Error resolving dependencies: %v", err) |
| 109 | } |
| 110 | ctx = ctx.WithDependencies(dependencies) |
| 111 | |
| 112 | // Execute plugin hook |
| 113 | err = hook.ExecuteHooks(ctx, nil, "print") |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | |
| 118 | if cmd.Dependency != "" { |
| 119 | dep := dependency.GetDependencyByPath(dependencies, cmd.Dependency) |
| 120 | if dep == nil { |
| 121 | return fmt.Errorf("couldn't find dependency %s: make sure it gets loaded correctly", cmd.Dependency) |
| 122 | } |
| 123 | |
| 124 | ctx = ctx.AsDependency(dep) |
| 125 | } |
| 126 | |
| 127 | bsConfig, err := marshalConfig(ctx.Config().Config(), cmd.StripNames) |
| 128 | if err != nil { |
no test coverage detected