| 27 | } |
| 28 | |
| 29 | export function createCli(args: string[], partialDependencies: Partial<CliDependencies> = {}): Argv { |
| 30 | const logger = partialDependencies.logger ?? createConsoleLogger(); |
| 31 | const dependencies: CliDependencies = { |
| 32 | createClient: partialDependencies.createClient ?? createCloudConvertClient, |
| 33 | runJob: |
| 34 | partialDependencies.runJob ?? |
| 35 | ((argv: CliArguments, taskData: TaskData) => |
| 36 | runJob(argv, taskData, { |
| 37 | spinner: ora('Creating job').start(), |
| 38 | logger |
| 39 | })), |
| 40 | logger, |
| 41 | exitProcess: partialDependencies.exitProcess ?? true |
| 42 | }; |
| 43 | |
| 44 | const cli = yargs(args) |
| 45 | .scriptName('cloudconvert') |
| 46 | .command(createConvertCommand(dependencies.runJob)) |
| 47 | .command(createOptimizeCommand(dependencies.runJob)) |
| 48 | .command(createMergeCommand(dependencies.runJob)) |
| 49 | .command(createCaptureWebsiteCommand(dependencies.runJob)) |
| 50 | .command(createThumbnailCommand(dependencies.runJob)) |
| 51 | .command(createWatermarkCommand(dependencies.runJob)) |
| 52 | .command(createCommandCommand(dependencies.runJob)) |
| 53 | .demandCommand() |
| 54 | .option('api-key', { |
| 55 | alias: 'apikey', |
| 56 | describe: 'Set the API key. You can get your API key here: https://cloudconvert.com/dashboard/api/v2/keys', |
| 57 | type: 'string', |
| 58 | default: process.env.CLOUDCONVERT_API_KEY, |
| 59 | defaultDescription: 'CLOUDCONVERT_API_KEY environment variable', |
| 60 | demandOption: true, |
| 61 | global: true |
| 62 | }) |
| 63 | .option('sandbox', { |
| 64 | describe: 'Use the CloudConvert Sandbox API', |
| 65 | type: 'boolean', |
| 66 | default: false, |
| 67 | global: true |
| 68 | }) |
| 69 | .option('output-dir', { |
| 70 | alias: 'outputdir', |
| 71 | describe: 'Set the directory for storing the output files. defaults to the working directory', |
| 72 | type: 'string', |
| 73 | global: true |
| 74 | }) |
| 75 | .option('overwrite', { |
| 76 | describe: 'Allow overwriting existing files', |
| 77 | type: 'boolean', |
| 78 | default: false, |
| 79 | global: true |
| 80 | }) |
| 81 | .option('parameter', { |
| 82 | alias: 'p', |
| 83 | describe: |
| 84 | 'Send custom parameters with the task payload. Prefer dynamic options such as --engine=office; -p.engine=office is kept for compatibility', |
| 85 | global: true |
| 86 | }) |