@bobfrankston/gcards 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/gfix.ts CHANGED
@@ -13,7 +13,7 @@ import path from 'path';
13
13
  import readline from 'readline';
14
14
  import type { GooglePerson, GoogleName, GooglePhoneNumber, GoogleEmailAddress, GoogleBirthday } from './glib/types.ts';
15
15
  import type { DeleteQueue, DeleteQueueEntry, UserPaths } from './glib/gctypes.ts';
16
- import { DATA_DIR, resolveUser, getUserPaths, loadIndex, getAllUsers, normalizeUser } from './glib/gutils.ts';
16
+ import { DATA_DIR, resolveUser, getUserPaths, loadIndex, getAllUsers, normalizeUser, matchUsers } from './glib/gutils.ts';
17
17
  import { mergeContacts as mergeContactData, collectSourcePhotos, type MergeEntry, type PhotoEntry } from './glib/gmerge.ts';
18
18
 
19
19
  function loadDeleteQueue(paths: UserPaths): DeleteQueue {
@@ -1445,13 +1445,7 @@ function findContactById(paths: UserPaths, id: string): { contact: GooglePerson;
1445
1445
  return null;
1446
1446
  }
1447
1447
 
1448
- /** Match users by partial name - returns matching user names */
1449
- function matchUsers(pattern: string): string[] {
1450
- const allUsers = getAllUsers();
1451
- const normalizedPattern = pattern.toLowerCase();
1452
1448
 
1453
- return allUsers.filter(user => user.toLowerCase().includes(normalizedPattern));
1454
- }
1455
1449
 
1456
1450
  /** Convert wildcard pattern to regex (supports * and ?) */
1457
1451
  function wildcardToRegex(pattern: string): RegExp {
package/glib/gutils.ts CHANGED
@@ -85,6 +85,32 @@ export function resolveUser(cliUser: string, setAsDefault = false): string {
85
85
  // 1. Use CLI-specified user if provided (and not 'default')
86
86
  if (cliUser && cliUser !== 'default') {
87
87
  const normalized = normalizeUser(cliUser);
88
+
89
+ // Check if this matches an existing user (exact or substring match)
90
+ const matches = matchUsers(normalized);
91
+
92
+ if (matches.length === 1) {
93
+ const matched = matches[0];
94
+ console.log(`Matched '${cliUser}' to existing user: ${matched}`);
95
+ if (setAsDefault) {
96
+ const config = loadConfig();
97
+ config.lastUser = matched;
98
+ saveConfig(config);
99
+ }
100
+ return matched;
101
+ } else if (matches.length > 1) {
102
+ console.error(`Ambiguous user '${cliUser}' matches multiple users: ${matches.join(', ')}`);
103
+ console.error('Please be more specific.');
104
+ process.exit(1);
105
+ }
106
+
107
+ // No match found - this is a new user, require email format with @
108
+ if (!cliUser.includes('@')) {
109
+ console.error(`New user '${cliUser}' must be specified as an email address (e.g., ${cliUser}@gmail.com)`);
110
+ process.exit(1);
111
+ }
112
+
113
+ // New user - use normalized version
88
114
  if (setAsDefault) {
89
115
  const config = loadConfig();
90
116
  config.lastUser = normalized;
@@ -109,6 +135,13 @@ export function normalizeUser(user: string): string {
109
135
  return user.toLowerCase().split(/[+@]/)[0].replace(/\./g, '');
110
136
  }
111
137
 
138
+ /** Match users by partial name (substring match) - returns matching user names */
139
+ export function matchUsers(pattern: string): string[] {
140
+ const allUsers = getAllUsers();
141
+ const normalizedPattern = pattern.toLowerCase();
142
+ return allUsers.filter(user => user.toLowerCase().includes(normalizedPattern));
143
+ }
144
+
112
145
  export function getAllUsers(): string[] {
113
146
  if (!fs.existsSync(DATA_DIR)) {
114
147
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/gcards",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Google Contacts cleanup and management tool",
5
5
  "type": "module",
6
6
  "main": "gcards.ts",