Skip to content

Dump files to the stdout if filename is specified. #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion cmd/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,36 @@ const output = outputter('stage', {
}
})

function getFileNameFromPearUrl(url) {
if (url.startsWith('pear://')) {
const urlParts = url.slice(7).split('/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use https://github.com/holepunchto/pear-link instead of manual parsing

const path = urlParts.slice(1).join('/')
if (path) {
const pathParts = path.split('/')
return pathParts[pathParts.length - 1]
Comment on lines +26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the return value is not used you could return a boolean instead

} else {
return null;
}
} else {
return null;
}
}

module.exports = (ipc) => async function dump (cmd) {
const { dryRun, checkout, json, ask, force } = cmd.flags
const { link } = cmd.args

let { dir } = cmd.args
if (!link) throw ERR_INVALID_INPUT('<link> must be specified.')
if (!dir) throw ERR_INVALID_INPUT('<dir> must be specified.')
dir = dir === '-' ? '-' : (isAbsolute(dir) ? dir : resolve('.', dir))
if (dir === '-') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dir === '-' || getFileNameFromPearUrl

dir = '-'
} else if (getFileNameFromPearUrl(link)) {
dir = '-'
}
else {
dir = isAbsolute(dir) ? dir : resolve('.', dir);
}

await output(json, ipc.dump({ id: Bare.pid, link, dir, dryRun, checkout, force }), { ask }, ipc)
}
4 changes: 2 additions & 2 deletions cmd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ module.exports = async (ipc, argv = Bare.argv.slice(1)) => {
const dump = command(
'dump',
summary('Synchronize files from key to dir'),
arg('<link>', 'Pear link to dump from, supports pathname'),
arg('<dir>', 'Directory path to dump to, may be - for stdout'),
arg('<link>', 'Pear link to dump from, supports pathname. Pathname will always dump the the stdout'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated "the" word

arg('<dir>', 'Directory path to dump to, may be - for stdout.'),
flag('--dry-run|-d', 'Execute a dump without writing'),
flag('--checkout <n>', 'Dump from specified checkout, n is version length'),
flag('--json', 'Newline delimited JSON output'),
Expand Down
Loading