mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08: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:
@@ -80,6 +80,17 @@ func (s *OptionSet) Add(opts ...Option) {
|
||||
*s = append(*s, opts...)
|
||||
}
|
||||
|
||||
// Filter will only return options that match the given filter. (return true)
|
||||
func (s OptionSet) Filter(filter func(opt Option) bool) OptionSet {
|
||||
cpy := make(OptionSet, 0)
|
||||
for _, opt := range s {
|
||||
if filter(opt) {
|
||||
cpy = append(cpy, opt)
|
||||
}
|
||||
}
|
||||
return cpy
|
||||
}
|
||||
|
||||
// FlagSet returns a pflag.FlagSet for the OptionSet.
|
||||
func (s *OptionSet) FlagSet() *pflag.FlagSet {
|
||||
if s == nil {
|
||||
|
||||
@@ -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