writeConfigMW will prevent the main command from running if the write-config flag is set. Instead, it will marshal the command options to YAML and write them to stdout.
(cfg *codersdk.DeploymentValues)
| 1498 | // flag is set. Instead, it will marshal the command options to YAML and write |
| 1499 | // them to stdout. |
| 1500 | func WriteConfigMW(cfg *codersdk.DeploymentValues) serpent.MiddlewareFunc { |
| 1501 | return func(next serpent.HandlerFunc) serpent.HandlerFunc { |
| 1502 | return func(inv *serpent.Invocation) error { |
| 1503 | if !cfg.WriteConfig { |
| 1504 | return next(inv) |
| 1505 | } |
| 1506 | |
| 1507 | opts := inv.Command.Options |
| 1508 | n, err := opts.MarshalYAML() |
| 1509 | if err != nil { |
| 1510 | return xerrors.Errorf("generate yaml: %w", err) |
| 1511 | } |
| 1512 | enc := yaml.NewEncoder(inv.Stdout) |
| 1513 | enc.SetIndent(2) |
| 1514 | err = enc.Encode(n) |
| 1515 | if err != nil { |
| 1516 | return xerrors.Errorf("encode yaml: %w", err) |
| 1517 | } |
| 1518 | err = enc.Close() |
| 1519 | if err != nil { |
| 1520 | return xerrors.Errorf("close yaml encoder: %w", err) |
| 1521 | } |
| 1522 | return nil |
| 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | // isLocalURL returns true if the hostname of the provided URL appears to |
| 1528 | // resolve to a loopback address. |
no test coverage detected