Accept Google Sheets URL in wizard and extract spreadsheet ID
This commit is contained in:
+31
-1
@@ -78,6 +78,33 @@ async function askOptionalPositiveInteger(ask, question, defaultValue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractSpreadsheetId(input) {
|
||||||
|
const value = (input || '').trim();
|
||||||
|
if (!value) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlMatch = value.match(/\/spreadsheets\/d\/([a-zA-Z0-9-_]+)/i);
|
||||||
|
if (urlMatch && urlMatch[1]) {
|
||||||
|
return urlMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function askSpreadsheetIdOrUrl(ask, question) {
|
||||||
|
while (true) {
|
||||||
|
const answer = await ask(question);
|
||||||
|
const documentId = extractSpreadsheetId(answer);
|
||||||
|
|
||||||
|
if (documentId) {
|
||||||
|
return documentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Please enter a Google Sheets URL or spreadsheet ID.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function pauseForEnter(ask) {
|
async function pauseForEnter(ask) {
|
||||||
await ask('Press Enter to close this window...');
|
await ask('Press Enter to close this window...');
|
||||||
}
|
}
|
||||||
@@ -176,7 +203,10 @@ async function runOnboarding() {
|
|||||||
const documentCount = await askPositiveInteger(ask, 'How many documents do you want to pull from? ');
|
const documentCount = await askPositiveInteger(ask, 'How many documents do you want to pull from? ');
|
||||||
|
|
||||||
for (let documentIndex = 0; documentIndex < documentCount; documentIndex += 1) {
|
for (let documentIndex = 0; documentIndex < documentCount; documentIndex += 1) {
|
||||||
const documentId = await askNonEmpty(ask, `Enter document ID ${documentIndex + 1}: `);
|
const documentId = await askSpreadsheetIdOrUrl(
|
||||||
|
ask,
|
||||||
|
`Enter Google Sheets URL or document ID ${documentIndex + 1}: `
|
||||||
|
);
|
||||||
let documentTitle = documentId;
|
let documentTitle = documentId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user