From 8f8b7a1df2664ded6566009968cb2bd556f31f15 Mon Sep 17 00:00:00 2001 From: bn-l Date: Fri, 5 Apr 2024 20:04:31 +1100 Subject: [PATCH] new echo feature --- README.md | 43 +-- coverage/coverage.txt | 6 +- coverage/lcov-report/cli.mts.html | 176 ++++++++----- coverage/lcov-report/index.html | 42 +-- coverage/lcov-report/main.mts.html | 138 +++++----- coverage/lcov.info | 406 +++++++++++++++-------------- package-lock.json | 31 ++- package.json | 5 +- somefolder/yoohoo.html | 36 +++ source/cli.mts | 101 ++++--- source/index.mts | 20 +- source/main.mts | 18 +- test/cli.unit.test.mts | 22 +- test/main.mocked.test.mts | 43 ++- test/main.online.e2e.test.mts | 61 +++-- 15 files changed, 680 insertions(+), 468 deletions(-) create mode 100644 somefolder/yoohoo.html diff --git a/README.md b/README.md index f3a38eb..ae97e7f 100644 --- a/README.md +++ b/README.md @@ -46,20 +46,20 @@ ghex [options] ### paths -One or more paths to download. Can be a whole -repo, a folder or a file. Supports globs but the path should be quoted. -To exclude use a negative glob ("!" at the beginning). -Can mix paths from different repos (conflicts resolved -left to right). A trailing slash means a whole folder. - +One or more paths to download. Can be a whole repo, or a +folder or a file within it. Supports globs but the path +should be quoted. To exclude use a negative glob ("!" at +the beginning). Can mix paths from different repos +(conflicts resolved left to right). A trailing slash means +a whole folder. Conflicting files are skipped by default. ## Options ### -l, --list List files. Useful as a dry run and with fzf. Does not -download. Will show show conflicts for the current -working directory if -d / --dest is not specified. +download. Will show show conflicts for the current working +directory or -d / --dest. ### -p, --prefix @@ -70,7 +70,7 @@ This is useful for feeding back into ghex. Only show conflicts when listing. -### -d, --dest folder +### -d, --dest (folder) Destination folder. Defaults to the current directory. @@ -79,20 +79,29 @@ Destination folder. Defaults to the current directory. Ignores case when checking for conflicts. Default is case-sensitive--i.e. casing matters. -### -k, --keep-if condition +### -f, --force + +Overwrite all existing conflicting files. Default false. -"newer" | "existing". Will keep conflicting files -if they exist or are newer. WARNING: The -default is to overwrite existing silently. +### -e, --echo-paths + +After writing, outputs the path of each file plus a new line. +Useful for piping to other commands. Also sets -quiet & +--no-color. ### -q, --quiet No success or error messages. -### --colors +### --no-prefix + +Remove the owner/repo prefix from the path in list output + +### --no-colors + +Strip ansi escape characters used to color output. +ghex respects the NO_COLOR env var if set also. -Use ansi escape characters to color output. -Default true but respects the NO_COLOR env var if set. ## Downloading Examples: @@ -132,3 +141,5 @@ npx ghex -l "facebook/react/.circleci/*" + + diff --git a/coverage/coverage.txt b/coverage/coverage.txt index daf072e..c98e5dc 100644 --- a/coverage/coverage.txt +++ b/coverage/coverage.txt @@ -1,7 +1,7 @@ ----------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ----------|---------|----------|---------|---------|------------------- -All files | 99.04 | 93.24 | 100 | 99.04 | - cli.mts | 97.98 | 95 | 100 | 97.98 | 139-141 - main.mts | 100 | 92.59 | 100 | 100 | 156-157 +All files | 100 | 100 | 100 | 100 | + cli.mts | 100 | 100 | 100 | 100 | + main.mts | 100 | 100 | 100 | 100 | ----------|---------|----------|---------|---------|------------------- diff --git a/coverage/lcov-report/cli.mts.html b/coverage/lcov-report/cli.mts.html index 968fdb8..c3b246d 100644 --- a/coverage/lcov-report/cli.mts.html +++ b/coverage/lcov-report/cli.mts.html @@ -23,16 +23,16 @@

All files cli.mts

- 97.98% + 100% Statements - 146/149 + 167/167
- 95% + 100% Branches - 19/20 + 22/22
@@ -44,9 +44,9 @@

All files cli.mts

- 97.98% + 100% Lines - 146/149 + 167/167
@@ -212,7 +212,27 @@

All files cli.mts

147 148 149 -1501x +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +1681x +1x +1x 1x 1x 1x @@ -220,10 +240,10 @@

All files cli.mts

1x 1x 1x +86x +86x 1x 1x -78x -78x 1x 1x 1x @@ -293,6 +313,10 @@

All files cli.mts

1x 1x 1x +1x +21x +21x +21x 21x 21x 21x @@ -349,18 +373,30 @@

All files cli.mts

21x 21x 21x -191x -  -  -  -191x 21x 21x +21x +21x +21x +21x +21x +2x +2x +2x +21x +21x +261x 1x 1x 1x +261x 20x -20x +21x +1x +1x +1x +19x +19x  
 
 import chalk from "chalk";
 import meow from "meow";
@@ -384,17 +420,20 @@ 

All files cli.mts

};     -const { name, docsUrl } = meow({ importMeta: import.meta }).pkg as { name: string; docsUrl: string }; +const { name, docsUrl } = { name: "ghex", docsUrl: "" };   export enum Option { - dest = "dest", list = "list", - prefix = "prefix", - colors = "colors", - caseInsensitive = "caseInsensitive", conflictsOnly = "conflictsOnly", - keepIf = "keepIf", + dest = "dest", + caseInsensitive = "caseInsensitive", + force = "force", + unwrap = "unwrap", + echoPaths = "echoPaths", quiet = "quiet", + prefix = "prefix", + colors = "colors", + debug = "debug", help = "help", version = "version", } @@ -403,28 +442,28 @@

All files cli.mts

Usage: ${ c.binColor(name) } [options] <paths...>   ${ c.strong("Arguments:") } - paths One or more paths to download. Can be a whole - repo, a folder or a file. ${ c.strong("Supports globs") } - but the path should be quoted. To exclude use a negative - glob ("!" at the beginning). Can mix paths from different - repos (conflicts resolved left to right). A trailing slash - means a whole folder. + paths One or more paths to download. Can be a whole repo, or a + folder or a file within it. ${ c.strong("Supports globs") } but the path + should be quoted. To exclude use a negative glob ("!" at + the beginning). Can mix paths from different repos + (conflicts resolved left to right). A trailing slash means + a whole folder. ${ c.strong("Conflicting files are skipped by default") }. ${ c.strong("Options:") } -l, --list List files. Useful as a dry run and with fzf. Does not - download. Will show show conflicts for the current - working directory if -d / --dest is not specified. - -p, --prefix Append the owner/repo prefix to the path in list output - Useful for feeding back into ${ name }. + download. Will show show conflicts for the current working + directory or -d / --dest. -c, --conflicts-only Only show conflicts when listing. -d, --dest <folder> Destination folder. Defaults to the current directory. -i, --case-insensitive Ignores case when checking for conflicts. Default is case-sensitive--i.e. casing matters. - -k, --keep-if <condition> "newer" | "existing". Will keep conflicting files - if they exist or are newer. ${ c.careful("WARNING:") } The - default is to overwrite existing silently. - -q, --quiet No success or error messages. - --colors Use ansi escape characters to color output. - Default true but respects the NO_COLOR env var if set. + -f, --force ${ c.strong("Overwrite all existing conflicting files. Default false.") } + -e, --echo-paths After writing, outputs the path of each file plus a new line. + Useful for piping to other commands. Also sets -quiet & + --no-color. + -q, --quiet No success or error messages. + --no-prefix Remove the owner/repo prefix from the path in list output + --no-colors Strip ansi escape characters used to color output. + ${ c.binColor(name) } respects the NO_COLOR env var if set also.   ${ c.strong("Download Examples:") } Entire repo ${ c.binColor(name) + " facebook/react" } @@ -450,63 +489,78 @@

All files cli.mts

type: "boolean", shortFlag: "l", }, - [Option.prefix]: { - type: "boolean", - shortFlag: "p", - }, - [Option.colors]: { - type: "boolean", - default: !noColor(), - }, [Option.conflictsOnly]: { type: "boolean", shortFlag: "c", }, + [Option.dest]: { + type: "string", + shortFlag: "d", + default: process.cwd(), + }, [Option.caseInsensitive]: { type: "boolean", shortFlag: "i", }, + [Option.force]: { + type: "boolean", + shortFlag: "f", + }, + [Option.unwrap]: { + type: "boolean", + shortFlag: "u", + }, + [Option.echoPaths]: { + type: "boolean", + shortFlag: "e", + }, [Option.quiet]: { type: "boolean", shortFlag: "q", default: false, }, - [Option.keepIf]: { - type: "string", - choices: ["newer", "existing"], + [Option.prefix]: { + type: "boolean", + default: true, + }, + [Option.colors]: { + type: "boolean", + default: !noColor(), + }, + [Option.debug]: { + type: "boolean", }, [Option.help]: { type: "boolean", - shortFlag: "h", }, [Option.version]: { type: "boolean", shortFlag: "v", }, - [Option.dest]: { - type: "string", - shortFlag: "d", - default: process.cwd(), - }, }, inferType: true, helpIndent: 3, - +  // if argv is defined, return an object to be spread. If not, expression evaluates // to undefined--which the spread operator ignores. ...(argv && { argv }), }); +  + if (cli.flags.echoPaths) { + cli.flags.quiet = true; + cli.flags.colors = false; + }   for (const flag of Object.keys(cli.flags)) { - if (!(flag in Option)) { - console.error(`\nError: Uknown flag "${ flag }". Run ${ name } -h to show help.\n`); - process.exit(1); - } + if (!(flag in Option)) { + console.error(`\nError: Uknown flag "${ flag }". Run ${ name } -h to show help.\n`); + process.exit(1); + } }   if (cli.input.length === 0) { console.error(`\nError: Need at least one path. Run ${ name } -h to show help.\n`); - process.exit(1); + process.exit(2); } return cli; } @@ -517,7 +571,7 @@

All files cli.mts