Skip to content

Commit

Permalink
new echo feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bn-l committed Apr 5, 2024
1 parent 56ce32b commit 8f8b7a1
Show file tree
Hide file tree
Showing 15 changed files with 680 additions and 468 deletions.
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ ghex [options] <paths...>

### 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

Expand All @@ -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.

Expand All @@ -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:

Expand Down Expand Up @@ -132,3 +141,5 @@ npx ghex -l "facebook/react/.circleci/*"

<!-- Everything after the snip is snipped off -->
<!-- SNIP -->


6 changes: 3 additions & 3 deletions coverage/coverage.txt
Original file line number Diff line number Diff line change
@@ -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 |
----------|---------|----------|---------|---------|-------------------
176 changes: 115 additions & 61 deletions coverage/lcov-report/cli.mts.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
<div class='clearfix'>

<div class='fl pad1y space-right2'>
<span class="strong">97.98% </span>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>146/149</span>
<span class='fraction'>167/167</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">95% </span>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>19/20</span>
<span class='fraction'>22/22</span>
</div>


Expand All @@ -44,9 +44,9 @@ <h1><a href="index.html">All files</a> cli.mts</h1>


<div class='fl pad1y space-right2'>
<span class="strong">97.98% </span>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>146/149</span>
<span class='fraction'>167/167</span>
</div>


Expand Down Expand Up @@ -212,18 +212,38 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
<a name='L147'></a><a href='#L147'>147</a>
<a name='L148'></a><a href='#L148'>148</a>
<a name='L149'></a><a href='#L149'>149</a>
<a name='L150'></a><a href='#L150'>150</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
<a name='L150'></a><a href='#L150'>150</a>
<a name='L151'></a><a href='#L151'>151</a>
<a name='L152'></a><a href='#L152'>152</a>
<a name='L153'></a><a href='#L153'>153</a>
<a name='L154'></a><a href='#L154'>154</a>
<a name='L155'></a><a href='#L155'>155</a>
<a name='L156'></a><a href='#L156'>156</a>
<a name='L157'></a><a href='#L157'>157</a>
<a name='L158'></a><a href='#L158'>158</a>
<a name='L159'></a><a href='#L159'>159</a>
<a name='L160'></a><a href='#L160'>160</a>
<a name='L161'></a><a href='#L161'>161</a>
<a name='L162'></a><a href='#L162'>162</a>
<a name='L163'></a><a href='#L163'>163</a>
<a name='L164'></a><a href='#L164'>164</a>
<a name='L165'></a><a href='#L165'>165</a>
<a name='L166'></a><a href='#L166'>166</a>
<a name='L167'></a><a href='#L167'>167</a>
<a name='L168'></a><a href='#L168'>168</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">86x</span>
<span class="cline-any cline-yes">86x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">78x</span>
<span class="cline-any cline-yes">78x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
Expand Down Expand Up @@ -293,6 +313,10 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
Expand Down Expand Up @@ -349,18 +373,30 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">191x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">191x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">261x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">261x</span>
<span class="cline-any cline-yes">20x</span>
<span class="cline-any cline-yes">20x</span>
<span class="cline-any cline-yes">21x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">19x</span>
<span class="cline-any cline-yes">19x</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">&nbsp;
import chalk from "chalk";
import meow from "meow";
Expand All @@ -384,17 +420,20 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
};
&nbsp;
&nbsp;
const { name, docsUrl } = meow({ importMeta: import.meta }).pkg as { name: string; docsUrl: string };
const { name, docsUrl } = { name: "ghex", docsUrl: "" };
&nbsp;
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",
}
Expand All @@ -403,28 +442,28 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
Usage: ${ c.binColor(name) } [options] &lt;paths...&gt;
&nbsp;
${ 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 &lt;folder&gt; 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 &lt;condition&gt; "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 &amp;
--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.
&nbsp;
${ c.strong("Download Examples:") }
Entire repo ${ c.binColor(name) + " facebook/react" }
Expand All @@ -450,63 +489,78 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
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,
&nbsp;
// if argv is defined, return an object to be spread. If not, expression evaluates
// to undefined--which the spread operator ignores.
...(argv &amp;&amp; { argv }),
});
&nbsp;
if (cli.flags.echoPaths) {
cli.flags.quiet = true;
cli.flags.colors = false;
}
&nbsp;
for (const flag of Object.keys(cli.flags)) {
if (!(flag in Option)) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
<span class="cstat-no" title="statement not covered" > console.error(`\nError: Uknown flag "${ flag }". Run ${ name } -h to show help.\n`);</span>
<span class="cstat-no" title="statement not covered" > process.exit(1);</span>
<span class="cstat-no" title="statement not covered" > }</span>
if (!(flag in Option)) {
console.error(`\nError: Uknown flag "${ flag }". Run ${ name } -h to show help.\n`);
process.exit(1);
}
}
&nbsp;
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;
}
Expand All @@ -517,7 +571,7 @@ <h1><a href="index.html">All files</a> cli.mts</h1>
<div class='footer quiet pad2 space-top1 center small'>
Code coverage generated by
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
at 2024-04-04T11:23:42.734Z
at 2024-04-05T09:03:51.987Z
</div>
<script src="prettify.js"></script>
<script>
Expand Down
Loading

0 comments on commit 8f8b7a1

Please sign in to comment.