Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/cli/src/commands/connector-sync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Command } from 'commander'
import { homedir } from 'node:os'
import { join } from 'node:path'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'

const __dirname = dirname(fileURLToPath(import.meta.url))
import {
getDB,
ConnectorRegistry,
Expand All @@ -19,10 +22,10 @@ import type { SyncState } from '@spool/core'

export const connectorSyncCommand = new Command('connector-sync')
.description('Sync a connector until fully complete')
.argument('[connector-id]', 'Connector ID (default: twitter-bookmarks)', 'twitter-bookmarks')
.argument('[connector-id]', 'Connector ID (omit to list available)')
.option('--reset', 'Delete all data for this connector and sync from scratch')
.option('--delay <ms>', 'Delay between page requests in ms', '600')
.action(async (connectorId: string, opts: { reset?: boolean; delay?: string }) => {
.action(async (connectorId: string | undefined, opts: { reset?: boolean; delay?: string }) => {
const db = getDB()
const registry = new ConnectorRegistry()
const spoolDir = join(homedir(), '.spool')
Expand All @@ -42,9 +45,22 @@ export const connectorSyncCommand = new Command('connector-sync')
trustStore: new TrustStore(spoolDir),
})

const available = registry.list().map(c => c.id)

if (!connectorId) {
if (available.length === 0) {
console.error('No connectors installed.')
process.exit(1)
}
console.log('Available connectors:')
for (const id of available) console.log(` ${id}`)
console.log('\nUsage: spool connector-sync <connector-id>')
process.exit(0)
}

if (!registry.has(connectorId)) {
console.error(`Unknown connector: ${connectorId}`)
console.error(`Available: ${registry.list().map(c => c.id).join(', ')}`)
console.error(`Available: ${available.join(', ')}`)
process.exit(1)
}

Expand Down