Skip to content

Commit

Permalink
✨ Ajout d'une commande pour copier des fichiers depuis la CLI (#2219)
Browse files Browse the repository at this point in the history
✨ Ajout d'une command pour copier des fichiers depuis la CLI
  • Loading branch information
JulienPavon committed Sep 19, 2024
1 parent c2f3a81 commit 0d3c4aa
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/applications/cli/src/commands/files/copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Command, Flags } from '@oclif/core';
import { z } from 'zod';

import { copyFile } from '@potentiel-libraries/file-storage';

import { parseCsvFile } from '../../helpers/parse-file';

const schema = z.object({
from: z.string(),
to: z.string(),
});

export default class FilesCopy extends Command {
static override description =
'Copy a list of files based on a CSV file that contains the list of new names.';

static override args = {};

static override flags = {
path: Flags.string({
char: 'p',
description: 'path to the csv file containing the files to copy',
required: true,
}),
};

public async run(): Promise<void> {
const { flags } = await this.parse(FilesCopy);
const { parsedData: files } = await parseCsvFile(flags.path, schema);

for (const file of files) {
try {
console.info(`Copying ${file.from} to ${file.to}`);
await copyFile(file.from, file.to);
console.debug(`Copied ${file.from} to ${file.to}`);
} catch (e) {
console.log(e);

console.error(`Error while copying ${file.from}`, e);
}
}
console.info(`Completed ${files.length} files`);
}
}

0 comments on commit 0d3c4aa

Please sign in to comment.