handle no file provided

This commit is contained in:
Tykayn 2023-07-19 17:41:51 +02:00 committed by tykayn
parent 0448f43553
commit 5ac004d194
2 changed files with 31 additions and 17 deletions

View File

@ -8,22 +8,14 @@ import rangement_instance from '../conf/configs'
import * as fs from "fs"; import * as fs from "fs";
import path from "node:path"; import path from "node:path";
import minimist from 'minimist'; import minimist from 'minimist';
import {fileDestructuration, taggingCommand} from './interfaces';
log.setLevel(rangement_instance.log_level) 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()) let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd())
/** /**
* finds patterns for file name * finds patterns for file name
*/ */
@ -81,7 +73,7 @@ export default class finder {
* @param fullPath * @param fullPath
*/ */
static guessFileNameOnOnefile(fullPath: string):void { static guessFileNameOnOnefile(fullPath: string): void {
log.info('go guess file name on file: ', fullPath) log.info('go guess file name on file: ', fullPath)
fs.stat(fullPath, (err, stats) => { fs.stat(fullPath, (err, stats) => {
@ -161,7 +153,7 @@ export default class finder {
}) })
} }
static guessFileNameOnAllFilesFromArguments():void { static guessFileNameOnAllFilesFromArguments(): void {
// parcourir les fichiers // parcourir les fichiers
log.debug('liste des fichiers', this.mini_arguments._) log.debug('liste des fichiers', this.mini_arguments._)
@ -212,6 +204,9 @@ export default class finder {
static parseArguments() { static parseArguments() {
this.mini_arguments = minimist(process.argv.slice(2)) this.mini_arguments = minimist(process.argv.slice(2))
log.debug('arguments', this.mini_arguments) 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) { static shouldWeChangeName(structureForFile: fileDestructuration) {
@ -357,7 +352,7 @@ export default class finder {
* @param tagCommand * @param tagCommand
* @returns {{tagsToAdd: [], tagCommand: *, tagsToRemove: []}} * @returns {{tagsToAdd: [], tagCommand: *, tagsToRemove: []}}
*/ */
static addOrRemoveTagsParsing(tagCommand: string): any { static addOrRemoveTagsParsing(tagCommand: string): taggingCommand {
let tagsToAdd: Array<any> = [] let tagsToAdd: Array<any> = []
let tagsToRemove: Array<any> = [] let tagsToRemove: Array<any> = []
@ -377,12 +372,15 @@ export default class finder {
} }
static applyTagChangesOnProperties(tagChange: any, properties: fileDestructuration) { static applyTagChangesOnProperties(tagChange: any, properties: fileDestructuration) {
// add new tags
properties.tags = [...properties.tags, tagChange.tagsToAdd] properties.tags = [...properties.tags, tagChange.tagsToAdd]
properties.tags.filter(elem => { properties.tags.forEach((elem, index) => {
return tagChange.tagsToRemove.includes(elem) if (tagChange.tagsToRemove.includes(elem)) {
delete properties.tags[index]
}
}) })
properties.tags = [...new Set(properties.tags)];
return properties return properties
} }

16
utils/interfaces.ts Normal file
View File

@ -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<string>,
tagsToRemove: Array<string>
}