Repository navigation
Expand file tree
/
Copy pathclient_options.go
More file actions
93 lines (84 loc) · 2.87 KB
/
Copy pathclient_options.go
File metadata and controls
93 lines (84 loc) · 2.87 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package things3
// clientOptions holds the configuration options for the Client.
type clientOptions struct {
// Database options
databasePath string
printSQL bool
// Scheme options
foreground bool // bring Things to foreground for create/update
background bool // keep Things in background for navigation
// Token options
preloadToken bool // fetch token immediately during NewClient
}
// ClientOption is a functional option for configuring the Client.
type ClientOption func(*clientOptions)
// WithDatabasePath sets a custom path to the Things database.
// If not set, the database path is discovered automatically.
//
// Example:
//
// client, err := things3.NewClient(things3.WithDatabasePath("/path/to/main.sqlite"))
func WithDatabasePath(path string) ClientOption {
return func(opts *clientOptions) {
opts.databasePath = path
}
}
// WithPrintSQL enables SQL query logging to stdout.
// Useful for debugging and understanding the queries being executed.
//
// Example:
//
// client, err := things3.NewClient(things3.WithPrintSQL(true))
func WithPrintSQL(enabled bool) ClientOption {
return func(opts *clientOptions) {
opts.printSQL = enabled
}
}
// WithForegroundExecution configures the Client to bring Things to foreground
// when executing create/update operations (AddTodo, AddProject, UpdateTodo, etc.).
//
// By default, create/update operations run in background without stealing focus.
// Use this option when you want Things to become the active window after operations.
//
// Example:
//
// client, err := things3.NewClient(things3.WithForegroundExecution())
// client.AddTodo().Title("Buy milk").Execute(ctx) // Things comes to foreground
func WithForegroundExecution() ClientOption {
return func(opts *clientOptions) {
opts.foreground = true
}
}
// WithBackgroundNavigation configures the Client to run navigation operations
// (Show, ShowList, ShowSearch) in the background without stealing focus.
//
// By default, navigation operations bring Things to foreground since
// the user typically wants to view the content.
// Use this option for programmatic navigation where focus change is undesired.
//
// Example:
//
// client, err := things3.NewClient(things3.WithBackgroundNavigation())
// client.Show(ctx, "uuid") // Things stays in background
func WithBackgroundNavigation() ClientOption {
return func(opts *clientOptions) {
opts.background = true
}
}
// WithPreloadToken fetches the authentication token immediately during NewClient()
// instead of lazily on first update operation.
//
// Use this option when you know you will need authenticated operations
// and want to fail fast if the token cannot be retrieved.
//
// Example:
//
// client, err := things3.NewClient(things3.WithPreloadToken())
// if err != nil {
// // May fail due to token retrieval error
// }
func WithPreloadToken() ClientOption {
return func(opts *clientOptions) {
opts.preloadToken = true
}
}