(ctx *cli.Context)
| 70 | } |
| 71 | |
| 72 | func getCfgBlockModule(ctx *cli.Context) (*container.C, module.Module, error) { |
| 73 | cfgPath := ctx.String("config") |
| 74 | if cfgPath == "" { |
| 75 | return nil, nil, cli.Exit("Error: config is required", 2) |
| 76 | } |
| 77 | |
| 78 | c := container.New() |
| 79 | container.Global = c |
| 80 | |
| 81 | cfg, err := maddy.ReadConfig(cfgPath) |
| 82 | if err != nil { |
| 83 | return nil, nil, cli.Exit(fmt.Sprintf("Error: failed to open config: %v", err), 2) |
| 84 | } |
| 85 | |
| 86 | globals, cfgNodes, err := maddy.ReadGlobals(c, cfg) |
| 87 | if err != nil { |
| 88 | return nil, nil, err |
| 89 | } |
| 90 | |
| 91 | // For CLI management we force-rollback configured logger and consider only |
| 92 | // --log so messages relevant to command execution will go where admin would |
| 93 | // see them. |
| 94 | c.DefaultLogger.Out = log.DefaultLogger.Out |
| 95 | |
| 96 | if err := maddy.InitDirs(c); err != nil { |
| 97 | return nil, nil, err |
| 98 | } |
| 99 | |
| 100 | err = maddy.RegisterModules(c, globals, cfgNodes) |
| 101 | if err != nil { |
| 102 | return nil, nil, err |
| 103 | } |
| 104 | |
| 105 | cfgBlock := ctx.String("cfg-block") |
| 106 | if cfgBlock == "" { |
| 107 | return nil, nil, cli.Exit("Error: cfg-block is required", 2) |
| 108 | } |
| 109 | |
| 110 | mod, err := c.Modules.Get(cfgBlock) |
| 111 | if err != nil { |
| 112 | if errors.Is(err, container.ErrInstanceUnknown) { |
| 113 | return nil, nil, cli.Exit(fmt.Sprintf("Error: unknown configuration block: %s", cfgBlock), 2) |
| 114 | } |
| 115 | return nil, nil, err |
| 116 | } |
| 117 | |
| 118 | return c, mod, nil |
| 119 | } |
| 120 | |
| 121 | func openStorage(ctx *cli.Context) (module.Storage, error) { |
| 122 | _, mod, err := getCfgBlockModule(ctx) |
no test coverage detected