Skip to content

Commit d2b79e0

Browse files
stainless-app[bot]batuhan
authored andcommitted
fix: better support passing client args in any position
1 parent e3829f7 commit d2b79e0

10 files changed

Lines changed: 80 additions & 36 deletions

internal/requestflag/requestflag.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,14 @@ func (f *Flag[T]) Count() int {
374374
return f.count
375375
}
376376

377+
// Implementation for the cli.LocalFlag interface
378+
var _ cli.LocalFlag = (*Flag[any])(nil) // Type assertion to ensure interface compliance
379+
380+
func (f Flag[T]) IsLocal() bool {
381+
// By default, all request flags are local, i.e. can be provided at any part of the CLI command.
382+
return true
383+
}
384+
377385
// cliValue is a generic implementation of cli.Value for common types
378386
type cliValue[
379387
T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string | []float64 |

pkg/cmd/account_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
func TestAccountsList(t *testing.T) {
1212
t.Run("regular flags", func(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
14-
t, "accounts", "list",
14+
t,
1515
"--access-token", "string",
16+
"accounts", "list",
1617
)
1718
})
1819
}

pkg/cmd/accountcontact_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
func TestAccountsContactsList(t *testing.T) {
1212
t.Run("regular flags", func(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
14-
t, "accounts:contacts", "list",
14+
t,
1515
"--access-token", "string",
16+
"accounts:contacts", "list",
1617
"--max-items", "10",
1718
"--account-id", "accountID",
1819
"--cursor", "1725489123456|c29tZUltc2dQYWdl",
@@ -26,8 +27,9 @@ func TestAccountsContactsList(t *testing.T) {
2627
func TestAccountsContactsSearch(t *testing.T) {
2728
t.Run("regular flags", func(t *testing.T) {
2829
mocktest.TestRunMockTestWithFlags(
29-
t, "accounts:contacts", "search",
30+
t,
3031
"--access-token", "string",
32+
"accounts:contacts", "search",
3133
"--account-id", "accountID",
3234
"--query", "x",
3335
)

pkg/cmd/asset_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
func TestAssetsDownload(t *testing.T) {
1212
t.Run("regular flags", func(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
14-
t, "assets", "download",
14+
t,
1515
"--access-token", "string",
16+
"assets", "download",
1617
"--url", "mxc://example.org/Q4x9CqGz1pB3Oa6XgJ",
1718
)
1819
})
@@ -21,17 +22,19 @@ func TestAssetsDownload(t *testing.T) {
2122
// Test piping YAML data over stdin
2223
pipeData := []byte("url: mxc://example.org/Q4x9CqGz1pB3Oa6XgJ")
2324
mocktest.TestRunMockTestWithPipeAndFlags(
24-
t, pipeData, "assets", "download",
25+
t, pipeData,
2526
"--access-token", "string",
27+
"assets", "download",
2628
)
2729
})
2830
}
2931

3032
func TestAssetsServe(t *testing.T) {
3133
t.Run("regular flags", func(t *testing.T) {
3234
mocktest.TestRunMockTestWithFlags(
33-
t, "assets", "serve",
35+
t,
3436
"--access-token", "string",
37+
"assets", "serve",
3538
"--url", "x",
3639
)
3740
})
@@ -40,8 +43,9 @@ func TestAssetsServe(t *testing.T) {
4043
func TestAssetsUpload(t *testing.T) {
4144
t.Run("regular flags", func(t *testing.T) {
4245
mocktest.TestRunMockTestWithFlags(
43-
t, "assets", "upload",
46+
t,
4447
"--access-token", "string",
48+
"assets", "upload",
4549
"--file", "Example data",
4650
"--file-name", "fileName",
4751
"--mime-type", "mimeType",
@@ -55,17 +59,19 @@ func TestAssetsUpload(t *testing.T) {
5559
"fileName: fileName\n" +
5660
"mimeType: mimeType\n")
5761
mocktest.TestRunMockTestWithPipeAndFlags(
58-
t, pipeData, "assets", "upload",
62+
t, pipeData,
5963
"--access-token", "string",
64+
"assets", "upload",
6065
)
6166
})
6267
}
6368

6469
func TestAssetsUploadBase64(t *testing.T) {
6570
t.Run("regular flags", func(t *testing.T) {
6671
mocktest.TestRunMockTestWithFlags(
67-
t, "assets", "upload-base64",
72+
t,
6873
"--access-token", "string",
74+
"assets", "upload-base64",
6975
"--content", "x",
7076
"--file-name", "fileName",
7177
"--mime-type", "mimeType",
@@ -79,8 +85,9 @@ func TestAssetsUploadBase64(t *testing.T) {
7985
"fileName: fileName\n" +
8086
"mimeType: mimeType\n")
8187
mocktest.TestRunMockTestWithPipeAndFlags(
82-
t, pipeData, "assets", "upload-base64",
88+
t, pipeData,
8389
"--access-token", "string",
90+
"assets", "upload-base64",
8491
)
8592
})
8693
}

pkg/cmd/beeperdesktopapi_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
func TestFocus(t *testing.T) {
1212
t.Run("regular flags", func(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
14-
t, "focus",
14+
t,
1515
"--access-token", "string",
16+
"focus",
1617
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
1718
"--draft-attachment-path", "draftAttachmentPath",
1819
"--draft-text", "draftText",
@@ -28,17 +29,19 @@ func TestFocus(t *testing.T) {
2829
"draftText: draftText\n" +
2930
"messageID: messageID\n")
3031
mocktest.TestRunMockTestWithPipeAndFlags(
31-
t, pipeData, "focus",
32+
t, pipeData,
3233
"--access-token", "string",
34+
"focus",
3335
)
3436
})
3537
}
3638

3739
func TestSearch(t *testing.T) {
3840
t.Run("regular flags", func(t *testing.T) {
3941
mocktest.TestRunMockTestWithFlags(
40-
t, "search",
42+
t,
4143
"--access-token", "string",
44+
"search",
4245
"--query", "x",
4346
)
4447
})

pkg/cmd/chat_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
func TestChatsCreate(t *testing.T) {
1313
t.Run("regular flags", func(t *testing.T) {
1414
mocktest.TestRunMockTestWithFlags(
15-
t, "chats", "create",
15+
t,
1616
"--access-token", "string",
17+
"chats", "create",
1718
"--account-id", "accountID",
1819
"--allow-invite=true",
1920
"--message-text", "messageText",
@@ -31,8 +32,9 @@ func TestChatsCreate(t *testing.T) {
3132

3233
// Alternative argument passing style using inner flags
3334
mocktest.TestRunMockTestWithFlags(
34-
t, "chats", "create",
35+
t,
3536
"--access-token", "string",
37+
"chats", "create",
3638
"--account-id", "accountID",
3739
"--allow-invite=true",
3840
"--message-text", "messageText",
@@ -66,17 +68,19 @@ func TestChatsCreate(t *testing.T) {
6668
" phoneNumber: phoneNumber\n" +
6769
" username: username\n")
6870
mocktest.TestRunMockTestWithPipeAndFlags(
69-
t, pipeData, "chats", "create",
71+
t, pipeData,
7072
"--access-token", "string",
73+
"chats", "create",
7174
)
7275
})
7376
}
7477

7578
func TestChatsRetrieve(t *testing.T) {
7679
t.Run("regular flags", func(t *testing.T) {
7780
mocktest.TestRunMockTestWithFlags(
78-
t, "chats", "retrieve",
81+
t,
7982
"--access-token", "string",
83+
"chats", "retrieve",
8084
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
8185
"--max-participant-count", "50",
8286
)
@@ -86,8 +90,9 @@ func TestChatsRetrieve(t *testing.T) {
8690
func TestChatsList(t *testing.T) {
8791
t.Run("regular flags", func(t *testing.T) {
8892
mocktest.TestRunMockTestWithFlags(
89-
t, "chats", "list",
93+
t,
9094
"--access-token", "string",
95+
"chats", "list",
9196
"--max-items", "10",
9297
"--account-id", "local-whatsapp_ba_EvYDBBsZbRQAy3UOSWqG0LuTVkc",
9398
"--account-id", "local-instagram_ba_eRfQMmnSNy_p7Ih7HL7RduRpKFU",
@@ -100,8 +105,9 @@ func TestChatsList(t *testing.T) {
100105
func TestChatsArchive(t *testing.T) {
101106
t.Run("regular flags", func(t *testing.T) {
102107
mocktest.TestRunMockTestWithFlags(
103-
t, "chats", "archive",
108+
t,
104109
"--access-token", "string",
110+
"chats", "archive",
105111
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
106112
"--archived=true",
107113
)
@@ -111,8 +117,9 @@ func TestChatsArchive(t *testing.T) {
111117
// Test piping YAML data over stdin
112118
pipeData := []byte("archived: true")
113119
mocktest.TestRunMockTestWithPipeAndFlags(
114-
t, pipeData, "chats", "archive",
120+
t, pipeData,
115121
"--access-token", "string",
122+
"chats", "archive",
116123
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
117124
)
118125
})
@@ -121,8 +128,9 @@ func TestChatsArchive(t *testing.T) {
121128
func TestChatsSearch(t *testing.T) {
122129
t.Run("regular flags", func(t *testing.T) {
123130
mocktest.TestRunMockTestWithFlags(
124-
t, "chats", "search",
131+
t,
125132
"--access-token", "string",
133+
"chats", "search",
126134
"--max-items", "10",
127135
"--account-id", "local-whatsapp_ba_EvYDBBsZbRQAy3UOSWqG0LuTVkc",
128136
"--account-id", "local-telegram_ba_QFrb5lrLPhO3OT5MFBeTWv0x4BI",

pkg/cmd/chatmessagereaction_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
func TestChatsMessagesReactionsDelete(t *testing.T) {
1212
t.Run("regular flags", func(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
14-
t, "chats:messages:reactions", "delete",
14+
t,
1515
"--access-token", "string",
16+
"chats:messages:reactions", "delete",
1617
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
1718
"--message-id", "messageID",
1819
"--reaction-key", "x",
@@ -23,8 +24,9 @@ func TestChatsMessagesReactionsDelete(t *testing.T) {
2324
func TestChatsMessagesReactionsAdd(t *testing.T) {
2425
t.Run("regular flags", func(t *testing.T) {
2526
mocktest.TestRunMockTestWithFlags(
26-
t, "chats:messages:reactions", "add",
27+
t,
2728
"--access-token", "string",
29+
"chats:messages:reactions", "add",
2830
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
2931
"--message-id", "messageID",
3032
"--reaction-key", "x",
@@ -38,8 +40,9 @@ func TestChatsMessagesReactionsAdd(t *testing.T) {
3840
"reactionKey: x\n" +
3941
"transactionID: transactionID\n")
4042
mocktest.TestRunMockTestWithPipeAndFlags(
41-
t, pipeData, "chats:messages:reactions", "add",
43+
t, pipeData,
4244
"--access-token", "string",
45+
"chats:messages:reactions", "add",
4346
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
4447
"--message-id", "messageID",
4548
)

pkg/cmd/chatreminder_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
func TestChatsRemindersCreate(t *testing.T) {
1313
t.Run("regular flags", func(t *testing.T) {
1414
mocktest.TestRunMockTestWithFlags(
15-
t, "chats:reminders", "create",
15+
t,
1616
"--access-token", "string",
17+
"chats:reminders", "create",
1718
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
1819
"--reminder", "{remindAtMs: 0, dismissOnIncomingMessage: true}",
1920
)
@@ -25,8 +26,9 @@ func TestChatsRemindersCreate(t *testing.T) {
2526

2627
// Alternative argument passing style using inner flags
2728
mocktest.TestRunMockTestWithFlags(
28-
t, "chats:reminders", "create",
29+
t,
2930
"--access-token", "string",
31+
"chats:reminders", "create",
3032
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
3133
"--reminder.remind-at-ms", "0",
3234
"--reminder.dismiss-on-incoming-message=true",
@@ -40,8 +42,9 @@ func TestChatsRemindersCreate(t *testing.T) {
4042
" remindAtMs: 0\n" +
4143
" dismissOnIncomingMessage: true\n")
4244
mocktest.TestRunMockTestWithPipeAndFlags(
43-
t, pipeData, "chats:reminders", "create",
45+
t, pipeData,
4446
"--access-token", "string",
47+
"chats:reminders", "create",
4548
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
4649
)
4750
})
@@ -50,8 +53,9 @@ func TestChatsRemindersCreate(t *testing.T) {
5053
func TestChatsRemindersDelete(t *testing.T) {
5154
t.Run("regular flags", func(t *testing.T) {
5255
mocktest.TestRunMockTestWithFlags(
53-
t, "chats:reminders", "delete",
56+
t,
5457
"--access-token", "string",
58+
"chats:reminders", "delete",
5559
"--chat-id", "!NCdzlIaMjZUmvmvyHU:beeper.com",
5660
)
5761
})

pkg/cmd/info_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
func TestInfoRetrieve(t *testing.T) {
1212
t.Run("regular flags", func(t *testing.T) {
1313
mocktest.TestRunMockTestWithFlags(
14-
t, "info", "retrieve",
14+
t,
1515
"--access-token", "string",
16+
"info", "retrieve",
1617
)
1718
})
1819
}

0 commit comments

Comments
 (0)