Skip to content

Commit

Permalink
Switch from gar to native args parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
atjn committed Jul 20, 2024
1 parent feaea73 commit 02c4ed7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The `fs` option allows you to pass a different filesystem handler, such as [memf
You can run this module from your command line:

```bash
get-folder-size --folder="/my/folder" --ignore="node_modules"
get-folder-size --folder "/my/folder" --ignore "node_modules"
```

The optional `ignore` statement takes a regex pattern.
Expand Down
27 changes: 20 additions & 7 deletions bin/get-folder-size.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
#!/usr/bin/env node

import getFolderSize from "../index.js";
import gar from "gar";
import path from "node:path";
import { parseArgs } from "node:util";
import { resolve } from "node:path";

const argv = gar(process.argv.slice(2));
const args = parseArgs({
args: process.argv.slice(2),
options: {
folder: {
short: "f",
type: "string",
},
ignore: {
short: "i",
type: "string",
},
},
allowPositionals: true,
});

// --folder or -f or last argument passed
const folder = argv.folder || argv.f || argv._[argv._.length - 1];
const folder = args.values.folder || args.positionals.at(-1);

if (!folder) {
console.error("missing folder argument");
console.error("\n Usage:\n");
console.error("get-folder-size --folder=/home/alex/www");
console.error(`get-folder-size --folder "/home/alex/www"`);
process.exit(1);
}

const ignore = argv.ignore || argv.i ? new RegExp(argv.ignore || argv.i) : null;
const ignore = args.values.ignore ? new RegExp(args.values.ignore) : undefined;

const size = await getFolderSize.strict(path.resolve(folder), { ignore });
const size = await getFolderSize.strict(resolve(folder), { ignore });
console.log((size / 1000 / 1000).toFixed(2) + " MB");
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"engines": {
"node": ">=18.11.0"
},
"dependencies": {
"gar": "^1.0.4"
},
"devDependencies": {
"@eslint/js": "^9.7.0",
"@types/eslint__js": "^8.42.3",
Expand Down

0 comments on commit 02c4ed7

Please sign in to comment.