Skip to content

Commit 5a8537c

Browse files
stainless-app[bot]batuhan
authored andcommitted
feat: improved documentation and flags for client options
1 parent 2934773 commit 5a8537c

13 files changed

Lines changed: 73 additions & 28 deletions

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,22 @@ beeper-desktop-cli [resource] <command> [flags...]
5353

5454
```sh
5555
beeper-desktop-cli chats search \
56-
--account-id local-whatsapp_ba_EvYDBBsZbRQAy3UOSWqG0LuTVkc \
57-
--account-id local-telegram_ba_QFrb5lrLPhO3OT5MFBeTWv0x4BI \
58-
--cursor '1725489123456|c29tZUltc2dQYWdl' \
59-
--direction before \
60-
--inbox primary \
6156
--include-muted \
62-
--last-activity-after 2019-12-27T18:11:19.117Z \
63-
--last-activity-before 2019-12-27T18:11:19.117Z \
6457
--limit 3 \
65-
--query x \
66-
--scope titles \
67-
--type single \
68-
--unread-only
58+
--type single
6959
```
7060

7161
For details about specific commands, use the `--help` flag.
7262

73-
### Global Flags
63+
### Environment variables
7464

65+
| Environment variable | Description | Required |
66+
| --------------------- | ----------------------------------------------------------------------------------------------------- | -------- |
67+
| `BEEPER_ACCESS_TOKEN` | Bearer access token obtained via OAuth2 PKCE flow or created in-app. Required for all API operations. | yes |
68+
69+
### Global flags
70+
71+
- `--access-token` - Bearer access token obtained via OAuth2 PKCE flow or created in-app. Required for all API operations. (can also be set with `BEEPER_ACCESS_TOKEN` env var)
7572
- `--help` - Show command line usage
7673
- `--debug` - Enable debug logging (includes HTTP request/response details)
7774
- `--version`, `-v` - Show the CLI version

internal/requestflag/requestflag.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ type Flag[
2020
[]float64 | []int64 | []bool | any | map[string]any | DateTimeValue | DateValue | TimeValue |
2121
string | float64 | int64 | bool,
2222
] struct {
23-
Name string // name of the flag
24-
Category string // category of the flag, if any
25-
DefaultText string // default text of the flag for usage purposes
26-
HideDefault bool // whether to hide the default value in output
27-
Usage string // usage string for help output
28-
Required bool // whether the flag is required or not
29-
Hidden bool // whether to hide the flag in help output
30-
Default T // default value for this flag if not set by from any source
31-
Aliases []string // aliases that are allowed for this flag
32-
Validator func(T) error // custom function to validate this flag value
23+
Name string // name of the flag
24+
Category string // category of the flag, if any
25+
DefaultText string // default text of the flag for usage purposes
26+
HideDefault bool // whether to hide the default value in output
27+
Usage string // usage string for help output
28+
Sources cli.ValueSourceChain // sources to load flag value from
29+
Required bool // whether the flag is required or not
30+
Hidden bool // whether to hide the flag in help output
31+
Default T // default value for this flag if not set by from any source
32+
Aliases []string // aliases that are allowed for this flag
33+
Validator func(T) error // custom function to validate this flag value
3334

3435
QueryPath string // location in the request query string to put this flag's value
3536
HeaderPath string // location in the request header to put this flag's value
@@ -127,6 +128,22 @@ func (f *Flag[T]) PreParse() error {
127128
}
128129

129130
func (f *Flag[T]) PostParse() error {
131+
if !f.hasBeenSet {
132+
if val, source, found := f.Sources.LookupWithSource(); found {
133+
if val != "" || reflect.TypeOf(f.value).Kind() == reflect.String {
134+
if err := f.Set(f.Name, val); err != nil {
135+
return fmt.Errorf(
136+
"could not parse %[1]q as %[2]T value from %[3]s for flag %[4]s: %[5]s",
137+
val, f.value, source, f.Name, err,
138+
)
139+
}
140+
} else if val == "" && reflect.TypeOf(f.value).Kind() == reflect.Bool {
141+
_ = f.Set(f.Name, "false")
142+
}
143+
144+
f.hasBeenSet = true
145+
}
146+
}
130147
return nil
131148
}
132149

@@ -230,8 +247,9 @@ func (f *Flag[T]) GetDefaultText() string {
230247
return f.DefaultText
231248
}
232249

250+
// GetEnvVars returns the env vars for this flag
233251
func (f *Flag[T]) GetEnvVars() []string {
234-
return nil
252+
return f.Sources.EnvKeys()
235253
}
236254

237255
func (f *Flag[T]) IsDefaultVisible() bool {

pkg/cmd/account_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ func TestAccountsList(t *testing.T) {
1212
mocktest.TestRunMockTestWithFlags(
1313
t,
1414
"accounts", "list",
15+
"--access-token", "string",
1516
)
1617
}

pkg/cmd/accountcontact_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestAccountsContactsList(t *testing.T) {
1212
mocktest.TestRunMockTestWithFlags(
1313
t,
1414
"accounts:contacts", "list",
15+
"--access-token", "string",
1516
"--account-id", "accountID",
1617
"--cursor", "1725489123456|c29tZUltc2dQYWdl",
1718
"--direction", "before",
@@ -24,6 +25,7 @@ func TestAccountsContactsSearch(t *testing.T) {
2425
mocktest.TestRunMockTestWithFlags(
2526
t,
2627
"accounts:contacts", "search",
28+
"--access-token", "string",
2729
"--account-id", "accountID",
2830
"--query", "x",
2931
)

pkg/cmd/asset_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestAssetsDownload(t *testing.T) {
1212
mocktest.TestRunMockTestWithFlags(
1313
t,
1414
"assets", "download",
15+
"--access-token", "string",
1516
"--url", "mxc://example.org/Q4x9CqGz1pB3Oa6XgJ",
1617
)
1718
}
@@ -20,6 +21,7 @@ func TestAssetsServe(t *testing.T) {
2021
mocktest.TestRunMockTestWithFlags(
2122
t,
2223
"assets", "serve",
24+
"--access-token", "string",
2325
"--url", "x",
2426
)
2527
}
@@ -28,7 +30,8 @@ func TestAssetsUpload(t *testing.T) {
2830
mocktest.TestRunMockTestWithFlags(
2931
t,
3032
"assets", "upload",
31-
"--file", "",
33+
"--access-token", "string",
34+
"--file", "...",
3235
"--file-name", "fileName",
3336
"--mime-type", "mimeType",
3437
)
@@ -38,6 +41,7 @@ func TestAssetsUploadBase64(t *testing.T) {
3841
mocktest.TestRunMockTestWithFlags(
3942
t,
4043
"assets", "upload-base64",
44+
"--access-token", "string",
4145
"--content", "x",
4246
"--file-name", "fileName",
4347
"--mime-type", "mimeType",

pkg/cmd/beeperdesktopapi_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestFocus(t *testing.T) {
1212
mocktest.TestRunMockTestWithFlags(
1313
t,
1414
"focus",
15+
"--access-token", "string",
1516
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
1617
"--draft-attachment-path", "draftAttachmentPath",
1718
"--draft-text", "draftText",
@@ -23,6 +24,7 @@ func TestSearch(t *testing.T) {
2324
mocktest.TestRunMockTestWithFlags(
2425
t,
2526
"search",
27+
"--access-token", "string",
2628
"--query", "x",
2729
)
2830
}

pkg/cmd/chat_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func TestChatsCreate(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
1414
t,
1515
"chats", "create",
16+
"--access-token", "string",
1617
"--account-id", "accountID",
1718
"--allow-invite=true",
1819
"--message-text", "messageText",
@@ -49,6 +50,7 @@ func TestChatsRetrieve(t *testing.T) {
4950
mocktest.TestRunMockTestWithFlags(
5051
t,
5152
"chats", "retrieve",
53+
"--access-token", "string",
5254
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
5355
"--max-participant-count", "50",
5456
)
@@ -58,6 +60,7 @@ func TestChatsList(t *testing.T) {
5860
mocktest.TestRunMockTestWithFlags(
5961
t,
6062
"chats", "list",
63+
"--access-token", "string",
6164
"--account-id", "local-whatsapp_ba_EvYDBBsZbRQAy3UOSWqG0LuTVkc",
6265
"--account-id", "local-instagram_ba_eRfQMmnSNy_p7Ih7HL7RduRpKFU",
6366
"--cursor", "1725489123456|c29tZUltc2dQYWdl",
@@ -69,6 +72,7 @@ func TestChatsArchive(t *testing.T) {
6972
mocktest.TestRunMockTestWithFlags(
7073
t,
7174
"chats", "archive",
75+
"--access-token", "string",
7276
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
7377
"--archived=true",
7478
)
@@ -78,14 +82,15 @@ func TestChatsSearch(t *testing.T) {
7882
mocktest.TestRunMockTestWithFlags(
7983
t,
8084
"chats", "search",
85+
"--access-token", "string",
8186
"--account-id", "local-whatsapp_ba_EvYDBBsZbRQAy3UOSWqG0LuTVkc",
8287
"--account-id", "local-telegram_ba_QFrb5lrLPhO3OT5MFBeTWv0x4BI",
8388
"--cursor", "1725489123456|c29tZUltc2dQYWdl",
8489
"--direction", "before",
8590
"--inbox", "primary",
8691
"--include-muted=true",
87-
"--last-activity-after", "2019-12-27T18:11:19.117Z",
88-
"--last-activity-before", "2019-12-27T18:11:19.117Z",
92+
"--last-activity-after", "'2019-12-27T18:11:19.117Z'",
93+
"--last-activity-before", "'2019-12-27T18:11:19.117Z'",
8994
"--limit", "1",
9095
"--query", "x",
9196
"--scope", "titles",

pkg/cmd/chatmessagereaction_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestChatsMessagesReactionsDelete(t *testing.T) {
1212
mocktest.TestRunMockTestWithFlags(
1313
t,
1414
"chats:messages:reactions", "delete",
15+
"--access-token", "string",
1516
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
1617
"--message-id", "messageID",
1718
"--reaction-key", "x",
@@ -22,6 +23,7 @@ func TestChatsMessagesReactionsAdd(t *testing.T) {
2223
mocktest.TestRunMockTestWithFlags(
2324
t,
2425
"chats:messages:reactions", "add",
26+
"--access-token", "string",
2527
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
2628
"--message-id", "messageID",
2729
"--reaction-key", "x",

pkg/cmd/chatreminder_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func TestChatsRemindersCreate(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
1414
t,
1515
"chats:reminders", "create",
16+
"--access-token", "string",
1617
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
1718
"--reminder", "{remindAtMs: 0, dismissOnIncomingMessage: true}",
1819
)
@@ -34,6 +35,7 @@ func TestChatsRemindersDelete(t *testing.T) {
3435
mocktest.TestRunMockTestWithFlags(
3536
t,
3637
"chats:reminders", "delete",
38+
"--access-token", "string",
3739
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
3840
)
3941
}

pkg/cmd/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/beeper/desktop-api-cli/internal/autocomplete"
15+
"github.com/beeper/desktop-api-cli/internal/requestflag"
1516
docs "github.com/urfave/cli-docs/v3"
1617
"github.com/urfave/cli/v3"
1718
)
@@ -66,6 +67,11 @@ func init() {
6667
Name: "transform-error",
6768
Usage: "The GJSON transformation for errors.",
6869
},
70+
&requestflag.Flag[string]{
71+
Name: "access-token",
72+
Usage: "Bearer access token obtained via OAuth2 PKCE flow or created in-app. Required for all API operations.",
73+
Sources: cli.EnvVars("BEEPER_ACCESS_TOKEN"),
74+
},
6975
},
7076
Commands: []*cli.Command{
7177
&focus,

0 commit comments

Comments
 (0)