From 8b329c930912a5def7a3517eb4772155971bb30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?elliot=20b=20=3D=5E=2E=5F=2E=5E=3D=20=E2=88=AB?= Date: Sat, 13 Jan 2024 18:53:45 -0500 Subject: [PATCH] some fixes, whoops --- cli.js | 21 +++++++++++++++------ index.js | 7 ++++--- lib/path-validation.js | 32 ++++++++++++++++++++++++++++---- readme.md | 12 +++++++----- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/cli.js b/cli.js index 16af6a6..36ce32f 100644 --- a/cli.js +++ b/cli.js @@ -13,12 +13,14 @@ const main = async () => { describe: 'silent mode; e.g no console.log describing new file names', type: 'boolean', + default: false, }) .option('v', { alias: 'verbose', describe: 'verbose mode; logs files renamed, as well as other useful information', type: 'boolean', + default: false, }) .option('d', { alias: 'dryrun', @@ -39,15 +41,17 @@ const main = async () => { describe: 'numbered mode: fuck all the other renaming schemes, and just numbered all files 1-??.', }) - .option('D', { + .option('f', { alias: 'dirs', describe: 'include directories', type: 'boolean', + default: false, }) .option('m', { alias: 'max-depth', describe: 'max depth', type: 'number', + default: -1, }) //options to list all available string modification functions .option('l', { @@ -59,7 +63,14 @@ const main = async () => { .alias('h', 'help') const argv = await parser.parse() - const globPattern = argv._[0] + let globPattern; + + if (argv._.length === 1) { + globPattern = argv._[0] + } + else { + globPattern = argv._ + } if (argv.l) { for (const [key] of Object.entries(stringModificationFunctions)) { let a = stringModificationFunctions[key] @@ -94,10 +105,8 @@ const main = async () => { } } let opts = userOpts - - - await detawks(globPattern, opts) - + //console.log(argv) + await detawks(globPattern, opts) } } main() diff --git a/index.js b/index.js index e360417..9e808dc 100644 --- a/index.js +++ b/index.js @@ -57,9 +57,10 @@ const run = async (globPattern, userOpts) => { let inputStr = await validateAndFormatInput(globPattern) console.log(`inputStr: ${JSON.stringify(inputStr)}`) let files - - if (inputStr.type === 'directory' || inputStr.type === 'glob') { - console.log(`inputStr.type: ${inputStr.path}`) + if (inputStr.type === 'fileArray') { + files = inputStr.files + } + else if (inputStr.type === 'directory' || inputStr.type === 'glob') { files = await useFdir( inputStr.path, opts.maxDepth, diff --git a/lib/path-validation.js b/lib/path-validation.js index 4aaa7df..4328e47 100644 --- a/lib/path-validation.js +++ b/lib/path-validation.js @@ -39,7 +39,7 @@ const getStats = async (inputStr) => { } const getFilePathType = async (inputStr) => { - let glob = await isStringAGlobPattern(inputStr); + let glob = await isStringAGlobPattern(inputStr) let [isDirectory, isFile] = await getStats(inputStr) if (isDirectory) { @@ -58,10 +58,34 @@ const getFilePathType = async (inputStr) => { //I realize this is convoluted, ah shit damn //verify CLI input is valid -export const validateAndFormatInput = async (inputStr) => { +export const validateAndFormatInput = async (inputStr, renameDirs = false) => { try { - //i like to do this as a amc user so just making that fix there - // inputStr = await replaceSquiglyWithHome(inputStr) + if (Array.isArray(inputStr)) { + try { + let filesArray = [] + for await (let file of inputStr) { + let abs = path.resolve(file) + if (renameDirs === false) { + let [isDirectory, isFile] = await getStats(abs) + if (isFile) { + filesArray.push(abs) + } + } + else { + filesArray.push(abs) + } + } + return { + type: 'fileArray', + files: filesArray + } + }catch(e) { + throw new Error(`error getting array of files from input: ${e}`) + + } + } + //i like to do this as a mac user so just making that fix there + // inputStr = await replaceSquiglyWithHome(inputStr) let type = await getFilePathType(inputStr) if (type === 'directory' || type === 'file') { diff --git a/readme.md b/readme.md index d4a3b2e..998f298 100644 --- a/readme.md +++ b/readme.md @@ -11,11 +11,13 @@ In your favorite terminal, run: detawks ``` ### Options -- `-s`: Silent mode (no console logs for new file names). -- `-d`: Dry run (shows potential file renames without executing them). -- `-r`: Overwrite mode (renames files automatically without prompting). -- `-f`: Includes directories in the operation. e.g. renames those too. -- `-m`: Specifies max depth for operations. +- `-s, --silent`: Silent mode (no console logs for new file names). +- `-d, --dryrun`: Dry run (shows potential file renames without executing them). +- `-f, --dirs`: Includes directories in the operation. e.g. renames those too. +- `-n, --numbered`: Just rename everything to an integer; 1-????. +- `-m, --max-depth`: Specifies max depth for operations. +- `-l, --list`: List all possible string operations. +- `-h, --help`: Show something approximating this, if I remember to update it. ## Config setup ### Location