mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
chore: Add workspace proxy enterprise cli commands (#7176)
* feat: Add workspace proxy enterprise cli commands * chore: Handle custom workspace proxy options. Remove excess * chore: Add endpoint to register workspace proxies
This commit is contained in:
@ -192,3 +192,35 @@ func (textFormat) AttachOptions(_ *clibase.OptionSet) {}
|
||||
func (textFormat) Format(_ context.Context, data any) (string, error) {
|
||||
return fmt.Sprintf("%s", data), nil
|
||||
}
|
||||
|
||||
// DataChangeFormat allows manipulating the data passed to an output format.
|
||||
// This is because sometimes the data needs to be manipulated before it can be
|
||||
// passed to the output format.
|
||||
// For example, you may want to pass something different to the text formatter
|
||||
// than what you pass to the json formatter.
|
||||
type DataChangeFormat struct {
|
||||
format OutputFormat
|
||||
change func(data any) (any, error)
|
||||
}
|
||||
|
||||
// ChangeFormatterData allows manipulating the data passed to an output
|
||||
// format.
|
||||
func ChangeFormatterData(format OutputFormat, change func(data any) (any, error)) *DataChangeFormat {
|
||||
return &DataChangeFormat{format: format, change: change}
|
||||
}
|
||||
|
||||
func (d *DataChangeFormat) ID() string {
|
||||
return d.format.ID()
|
||||
}
|
||||
|
||||
func (d *DataChangeFormat) AttachOptions(opts *clibase.OptionSet) {
|
||||
d.format.AttachOptions(opts)
|
||||
}
|
||||
|
||||
func (d *DataChangeFormat) Format(ctx context.Context, data any) (string, error) {
|
||||
newData, err := d.change(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return d.format.Format(ctx, newData)
|
||||
}
|
||||
|
Reference in New Issue
Block a user