-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Ajout d'une command pour copier des fichiers depuis la CLI
- Loading branch information
1 parent
c2f3a81
commit 71b3e2b
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
} |