Skip to content

Commit 58d48dc

Browse files
committed
Add display name support for accounts
1 parent 493e286 commit 58d48dc

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

cmd/msgvault/cmd/addaccount.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
)
1010

1111
var (
12-
headless bool
12+
headless bool
13+
accountDisplayName string
1314
)
1415

1516
var addAccountCmd = &cobra.Command{
@@ -20,9 +21,10 @@ var addAccountCmd = &cobra.Command{
2021
By default, opens a browser for authorization. Use --headless for environments
2122
without a display (e.g., SSH sessions) to use device code flow instead.
2223
23-
Example:
24+
Examples:
2425
msgvault add-account you@gmail.com
25-
msgvault add-account you@gmail.com --headless`,
26+
msgvault add-account you@gmail.com --headless
27+
msgvault add-account you@gmail.com --display-name "Work Account"`,
2628
Args: cobra.ExactArgs(1),
2729
RunE: func(cmd *cobra.Command, args []string) error {
2830
email := args[0]
@@ -70,11 +72,18 @@ Example:
7072
}
7173

7274
// Create source record in database
73-
_, err = s.GetOrCreateSource("gmail", email)
75+
source, err := s.GetOrCreateSource("gmail", email)
7476
if err != nil {
7577
return fmt.Errorf("create source: %w", err)
7678
}
7779

80+
// Set display name if provided
81+
if accountDisplayName != "" {
82+
if err := s.UpdateSourceDisplayName(source.ID, accountDisplayName); err != nil {
83+
return fmt.Errorf("set display name: %w", err)
84+
}
85+
}
86+
7887
fmt.Printf("\nAccount %s authorized successfully!\n", email)
7988
fmt.Println("You can now run: msgvault sync-full", email)
8089

@@ -84,5 +93,6 @@ Example:
8493

8594
func init() {
8695
addAccountCmd.Flags().BoolVar(&headless, "headless", false, "Use device code flow for headless environments")
96+
addAccountCmd.Flags().StringVar(&accountDisplayName, "display-name", "", "Display name for the account (e.g., \"Work\", \"Personal\")")
8797
rootCmd.AddCommand(addAccountCmd)
8898
}

cmd/msgvault/cmd/update_account.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/wesm/msgvault/internal/store"
8+
)
9+
10+
var updateDisplayName string
11+
12+
var updateAccountCmd = &cobra.Command{
13+
Use: "update-account <email>",
14+
Short: "Update account settings",
15+
Long: `Update settings for an existing account.
16+
17+
Currently supports updating the display name for an account.
18+
19+
Examples:
20+
msgvault update-account you@gmail.com --display-name "Work"
21+
msgvault update-account you@gmail.com --display-name "Personal Email"`,
22+
Args: cobra.ExactArgs(1),
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
email := args[0]
25+
26+
if updateDisplayName == "" {
27+
return fmt.Errorf("nothing to update: use --display-name to set a display name")
28+
}
29+
30+
dbPath := cfg.DatabasePath()
31+
s, err := store.Open(dbPath)
32+
if err != nil {
33+
return fmt.Errorf("open database: %w", err)
34+
}
35+
defer s.Close()
36+
37+
source, err := s.GetSourceByIdentifier(email)
38+
if err != nil {
39+
return fmt.Errorf("get account: %w", err)
40+
}
41+
if source == nil {
42+
return fmt.Errorf("account not found: %s", email)
43+
}
44+
45+
if err := s.UpdateSourceDisplayName(source.ID, updateDisplayName); err != nil {
46+
return fmt.Errorf("update display name: %w", err)
47+
}
48+
49+
fmt.Printf("Updated account %s: display name set to %q\n", email, updateDisplayName)
50+
return nil
51+
},
52+
}
53+
54+
func init() {
55+
rootCmd.AddCommand(updateAccountCmd)
56+
updateAccountCmd.Flags().StringVar(&updateDisplayName, "display-name", "", "Set the display name for the account")
57+
}

internal/store/sync.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ func (s *Store) UpdateSourceSyncCursor(sourceID int64, cursor string) error {
245245
return err
246246
}
247247

248+
// UpdateSourceDisplayName updates the display name for a source.
249+
func (s *Store) UpdateSourceDisplayName(sourceID int64, displayName string) error {
250+
_, err := s.db.Exec(`
251+
UPDATE sources
252+
SET display_name = ?, updated_at = datetime('now')
253+
WHERE id = ?
254+
`, displayName, sourceID)
255+
return err
256+
}
257+
248258
// GetSourceByIdentifier returns a source by its identifier (email address).
249259
func (s *Store) GetSourceByIdentifier(identifier string) (*Source, error) {
250260
row := s.db.QueryRow(`

0 commit comments

Comments
 (0)