-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathfilter.go
More file actions
63 lines (57 loc) · 1.28 KB
/
filter.go
File metadata and controls
63 lines (57 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cliui
import (
"github.com/coder/coder/v2/codersdk"
"github.com/coder/serpent"
)
var defaultQuery = "owner:me"
// WorkspaceFilter wraps codersdk.WorkspaceFilter
// and allows easy integration to a CLI command.
// Example usage:
//
// func (r *RootCmd) MyCmd() *serpent.Command {
// var (
// filter cliui.WorkspaceFilter
// ...
// )
// cmd := &serpent.Command{
// ...
// }
// filter.AttachOptions(&cmd.Options)
// ...
// return cmd
// }
//
// The above will add the following flags to the command:
// --all
// --search
type WorkspaceFilter struct {
searchQuery string
all bool
}
func (w *WorkspaceFilter) Filter() codersdk.WorkspaceFilter {
var f codersdk.WorkspaceFilter
if w.all {
return f
}
f.FilterQuery = w.searchQuery
if f.FilterQuery == "" {
f.FilterQuery = defaultQuery
}
return f
}
func (w *WorkspaceFilter) AttachOptions(opts *serpent.OptionSet) {
*opts = append(*opts,
serpent.Option{
Flag: "all",
FlagShorthand: "a",
Description: "Specifies whether all workspaces will be listed or not.",
Value: serpent.BoolOf(&w.all),
},
serpent.Option{
Flag: "search",
Description: "Search for a workspace with a query.",
Default: defaultQuery,
Value: serpent.StringOf(&w.searchQuery),
},
)
}