From 5ac004d19415fa32857a9c8db244cf66a4c37484 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 19 Jul 2023 17:41:51 +0200 Subject: [PATCH] handle no file provided --- utils/finder.ts | 32 +++++++++++++++----------------- utils/interfaces.ts | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 utils/interfaces.ts diff --git a/utils/finder.ts b/utils/finder.ts index afaf6e5..4c7293d 100644 --- a/utils/finder.ts +++ b/utils/finder.ts @@ -8,22 +8,14 @@ import rangement_instance from '../conf/configs' import * as fs from "fs"; import path from "node:path"; import minimist from 'minimist'; +import {fileDestructuration, taggingCommand} from './interfaces'; log.setLevel(rangement_instance.log_level) -interface fileDestructuration { - fullPath: string - folderPath: string - fileNameOriginal: string - dateStampInFileNameOriginal: string - dateStampExif: string, - freeText: string, - tags: string[], - extension: string, -} let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + /** * finds patterns for file name */ @@ -81,7 +73,7 @@ export default class finder { * @param fullPath */ - static guessFileNameOnOnefile(fullPath: string):void { + static guessFileNameOnOnefile(fullPath: string): void { log.info('go guess file name on file: ', fullPath) fs.stat(fullPath, (err, stats) => { @@ -161,7 +153,7 @@ export default class finder { }) } - static guessFileNameOnAllFilesFromArguments():void { + static guessFileNameOnAllFilesFromArguments(): void { // parcourir les fichiers log.debug('liste des fichiers', this.mini_arguments._) @@ -212,6 +204,9 @@ export default class finder { static parseArguments() { this.mini_arguments = minimist(process.argv.slice(2)) log.debug('arguments', this.mini_arguments) + if (!this.mini_arguments._.length) { + log.info('pas de fichier ou de dossier demandé, veuillez spécifier un chemin en argument') + } } static shouldWeChangeName(structureForFile: fileDestructuration) { @@ -357,7 +352,7 @@ export default class finder { * @param tagCommand * @returns {{tagsToAdd: [], tagCommand: *, tagsToRemove: []}} */ - static addOrRemoveTagsParsing(tagCommand: string): any { + static addOrRemoveTagsParsing(tagCommand: string): taggingCommand { let tagsToAdd: Array = [] let tagsToRemove: Array = [] @@ -377,12 +372,15 @@ export default class finder { } static applyTagChangesOnProperties(tagChange: any, properties: fileDestructuration) { - - + // add new tags properties.tags = [...properties.tags, tagChange.tagsToAdd] - properties.tags.filter(elem => { - return tagChange.tagsToRemove.includes(elem) + properties.tags.forEach((elem, index) => { + if (tagChange.tagsToRemove.includes(elem)) { + delete properties.tags[index] + } }) + properties.tags = [...new Set(properties.tags)]; + return properties } diff --git a/utils/interfaces.ts b/utils/interfaces.ts new file mode 100644 index 0000000..6db4fe6 --- /dev/null +++ b/utils/interfaces.ts @@ -0,0 +1,16 @@ +export interface fileDestructuration { + fullPath: string + folderPath: string + fileNameOriginal: string + dateStampInFileNameOriginal: string + dateStampExif: string, + freeText: string, + tags: string[], + extension: string, +} + +export interface taggingCommand { + tagCommand: string, + tagsToAdd: Array, + tagsToRemove: Array +} \ No newline at end of file