(argv: Arguments<PullOptions>)
| 33 | }; |
| 34 | |
| 35 | export const handler = async (argv: Arguments<PullOptions>): Promise<void> => { |
| 36 | console.log(chalk.cyan('\n📥 Pulling Tianji Worker from remote...\n')); |
| 37 | |
| 38 | try { |
| 39 | // Check if user is logged in |
| 40 | if (!(await isLoggedIn())) { |
| 41 | console.error( |
| 42 | chalk.red('Error: Not logged in. Please run "tianji login" first.\n') |
| 43 | ); |
| 44 | process.exit(1); |
| 45 | } |
| 46 | |
| 47 | // Load global config |
| 48 | const globalConfig = await loadGlobalConfig(); |
| 49 | if (!globalConfig) { |
| 50 | console.error( |
| 51 | chalk.red( |
| 52 | 'Error: Configuration not found. Please run "tianji login" first.\n' |
| 53 | ) |
| 54 | ); |
| 55 | process.exit(1); |
| 56 | } |
| 57 | |
| 58 | const currentDir = process.cwd(); |
| 59 | const projectConfig = await loadProjectConfig(currentDir); |
| 60 | const hasTianjirc = projectConfig !== null; |
| 61 | |
| 62 | // Determine worker ID |
| 63 | let workerId: string | undefined; |
| 64 | if (argv.workerId) { |
| 65 | // Command line argument takes priority |
| 66 | workerId = argv.workerId; |
| 67 | } else if (hasTianjirc && projectConfig.workerId) { |
| 68 | // Use worker ID from .tianjirc |
| 69 | workerId = projectConfig.workerId; |
| 70 | } |
| 71 | |
| 72 | if (!workerId) { |
| 73 | console.error( |
| 74 | chalk.red( |
| 75 | 'Error: Worker ID is required. Please provide it as an argument or ensure .tianjirc contains a workerId.\n' |
| 76 | ) |
| 77 | ); |
| 78 | console.log(chalk.white('Usage: tianji worker pull <worker-id>\n')); |
| 79 | process.exit(1); |
| 80 | } |
| 81 | |
| 82 | // Check directory status |
| 83 | const files = await fs.readdir(currentDir); |
| 84 | const isEmptyDir = files.length === 0; |
| 85 | |
| 86 | if (!hasTianjirc && !isEmptyDir) { |
| 87 | // Directory is not empty and not a Tianji worker project |
| 88 | console.error( |
| 89 | chalk.red( |
| 90 | 'Error: Current directory is not empty and is not a Tianji worker project.\n' |
| 91 | ) |
| 92 | ); |
nothing calls this directly
no test coverage detected