handle no file provided
This commit is contained in:
parent
0448f43553
commit
5ac004d194
|
@ -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<any> = []
|
||||
let tagsToRemove: Array<any> = []
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
}
|
Loading…
Reference in New Issue