MCPcopy Index your code
hub / github.com/coder/coder / WriteConfigMW

Function WriteConfigMW

cli/server.go:1500–1525  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1498// flag is set. Instead, it will marshal the command options to YAML and write
1499// them to stdout.
1500func 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.

Callers 2

proxyServerMethod · 0.92
ServerMethod · 0.85

Calls 3

EncodeMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected