Skip to content

Commit

Permalink
some fixes, whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotberry committed Jan 13, 2024
1 parent 5dc1e23 commit 8b329c9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
21 changes: 15 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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', {
Expand All @@ -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]
Expand Down Expand Up @@ -94,10 +105,8 @@ const main = async () => {
}
}
let opts = userOpts


await detawks(globPattern, opts)

//console.log(argv)
await detawks(globPattern, opts)
}
}
main()
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 28 additions & 4 deletions lib/path-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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') {
Expand Down
12 changes: 7 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ In your favorite terminal, run:
detawks <options> <glob / directory / file>
```
### 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
Expand Down

0 comments on commit 8b329c9

Please sign in to comment.