Skip to content

Commit 702577c

Browse files
authored
chore(loo-4788): --debug flag (#29)
1 parent 05f93c4 commit 702577c

18 files changed

Lines changed: 78 additions & 38 deletions

cmd/api_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func runAPIKey(cfg *config.Config) (*api.APIKeyResponse, error) {
12-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).GetAPIKey()
12+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).GetAPIKey()
1313
}
1414

1515
var apiKeyCmd = &cobra.Command{

cmd/auth_login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func runAuthLogin(apiKey, name string) (*api.APIKeyResponse, error) {
5151
if name == "" {
5252
return nil, errors.New("use --name to give this key a name")
5353
}
54-
result, err := api.NewClient(config.EndpointURL(), apiKey).GetAPIKey()
54+
result, err := api.NewClient(config.EndpointURL(), apiKey, debugFlag).GetAPIKey()
5555
if err != nil {
5656
return nil, fmt.Errorf("API key verification failed: %w", err)
5757
}

cmd/auth_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func runAuthStatus() (*config.Config, *api.APIKeyResponse, *config.PersistentCon
4747
if err != nil {
4848
return nil, nil, nil, err
4949
}
50-
keyResp, err := api.NewClient(cfg.EndpointURL, cfg.APIKey).GetAPIKey()
50+
keyResp, err := api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).GetAPIKey()
5151
if err != nil {
5252
return nil, nil, nil, fmt.Errorf("API key verification failed: %w", err)
5353
}

cmd/contact_properties.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
)
1010

1111
func runContactPropertiesList(cfg *config.Config, customOnly bool) ([]api.ContactProperty, error) {
12-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).ListContactProperties(customOnly)
12+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).ListContactProperties(customOnly)
1313
}
1414

1515
func runContactPropertiesCreate(cfg *config.Config, name, propType string) error {
16-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).CreateContactProperty(name, propType)
16+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).CreateContactProperty(name, propType)
1717
}
1818

1919
var contactPropertiesCmd = &cobra.Command{

cmd/contacts.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func contactFieldParamsFromCmd(cmd *cobra.Command) (contactFieldParams, error) {
7777
// find
7878

7979
func runContactsFind(cfg *config.Config, email, userID string) ([]api.Contact, error) {
80-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).FindContacts(api.FindContactParams{
80+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).FindContacts(api.FindContactParams{
8181
Email: email,
8282
UserID: userID,
8383
})
@@ -149,7 +149,7 @@ type contactCreateResult struct {
149149
}
150150

151151
func runContactsCreate(cfg *config.Config, req api.CreateContactRequest) (string, error) {
152-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).CreateContact(req)
152+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).CreateContact(req)
153153
}
154154

155155
var contactsCreateCmd = &cobra.Command{
@@ -196,7 +196,7 @@ var contactsCreateCmd = &cobra.Command{
196196
// update
197197

198198
func runContactsUpdate(cfg *config.Config, req api.UpdateContactRequest) error {
199-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).UpdateContact(req)
199+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).UpdateContact(req)
200200
}
201201

202202
var contactsUpdateCmd = &cobra.Command{
@@ -244,7 +244,7 @@ var contactsUpdateCmd = &cobra.Command{
244244
// delete
245245

246246
func runContactsDelete(cfg *config.Config, email, userID string) error {
247-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).DeleteContact(email, userID)
247+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).DeleteContact(email, userID)
248248
}
249249

250250
var contactsDeleteCmd = &cobra.Command{

cmd/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func parseMailingLists(pairs []string) (map[string]bool, error) {
3535
}
3636

3737
func runEventsSend(cfg *config.Config, req api.SendEventRequest) error {
38-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).SendEvent(req)
38+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).SendEvent(req)
3939
}
4040

4141
var eventsCmd = &cobra.Command{

cmd/lists.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func runListsList(cfg *config.Config) ([]api.MailingList, error) {
12-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).ListMailingLists()
12+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).ListMailingLists()
1313
}
1414

1515
var listsCmd = &cobra.Command{

cmd/root.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ import (
1313

1414
var outputFormat outputFlag = "text"
1515
var teamFlag string
16+
var debugFlag bool
1617

1718
func loadConfig() (*config.Config, error) {
18-
return config.Load(teamFlag)
19+
cfg, err := config.Load(teamFlag)
20+
if err != nil {
21+
return nil, err
22+
}
23+
cfg.Debug = debugFlag
24+
return cfg, nil
1925
}
2026

2127
var rootCmd = &cobra.Command{
@@ -66,4 +72,5 @@ func init() {
6672
// when this action is called directly.
6773
rootCmd.PersistentFlags().VarP(&outputFormat, "output", "o", "Output format (text, json)")
6874
rootCmd.PersistentFlags().StringVarP(&teamFlag, "team", "t", "", "Team key name to use")
75+
rootCmd.PersistentFlags().BoolVar(&debugFlag, "debug", false, "Print API request details before sending")
6976
}

cmd/transactional.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func attachmentFromPath(path string) (api.Attachment, error) {
6464
}
6565

6666
func runTransactionalList(cfg *config.Config, params api.PaginationParams) ([]api.TransactionalEmail, error) {
67-
client := api.NewClient(cfg.EndpointURL, cfg.APIKey)
67+
client := api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug)
6868
if params.Cursor != "" {
6969
emails, _, err := client.ListTransactional(params)
7070
return emails, err
@@ -78,7 +78,7 @@ func runTransactionalList(cfg *config.Config, params api.PaginationParams) ([]ap
7878
}
7979

8080
func runTransactionalSend(cfg *config.Config, req api.SendTransactionalRequest) error {
81-
return api.NewClient(cfg.EndpointURL, cfg.APIKey).SendTransactional(req)
81+
return api.NewClient(cfg.EndpointURL, cfg.APIKey, cfg.Debug).SendTransactional(req)
8282
}
8383

8484
var transactionalCmd = &cobra.Command{

internal/api/api_key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestGetAPIKey(t *testing.T) {
5151
}))
5252
defer server.Close()
5353

54-
client := NewClient(server.URL, "test-key")
54+
client := NewClient(server.URL, "test-key", false)
5555
result, err := client.GetAPIKey()
5656

5757
if tt.wantAPIErr != nil {

0 commit comments

Comments
 (0)