Skip to content
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

Add --copy option. #32

Open
wants to merge 17 commits into
base: master
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
168 changes: 88 additions & 80 deletions lib/commands/beam.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,88 @@
import Hyperbeam from 'hyperbeam'
import randomWords from 'random-words'
import chalk from 'chalk'

const FULL_USAGE = `
The beam command is a general-purpose tool for sending data over the network
according to a secret passphrase. You choose a phrase (try to make it hard-ish
to guess!) and then share the phrase with your recipient. The phrase is only
good for 30-60 minutes.

On the sending device:

cat hello.txt | hyp beam "for bob roberts"

On the receiving device:

hyp beam "for bob roberts" > ./hello.txt

This can be really useful for sharing hyper keys between devices. For instance:

> hyp sync ./my-folder
Creating new hyperdrive...
Source: my-folder/
Target: hyper://f7145e1bbc0d17705861e996b47422e0ca50a80db9441249bd721ff426b79f2a/
Begin sync? [y/N] y
Syncing...
Synced
> echo "hyper://f7145e1bbc0d17705861e996b47422e0ca50a80db9441249bd721ff426b79f2a/" \\
| hyp beam "nobody can guess"
`

export default {
name: 'beam',
description: 'Send a stream of data over the network.',
usage: {
simple: '[passphrase]',
full: FULL_USAGE
},
command: async function (args) {
var phrase = args._[0] ? args._.join(' ') : randomWords(3).join(' ')
const beam = new Hyperbeam(phrase)

if (!args._[0]) {
console.error('[hyperbeam] Generated passphrase:')
console.error('')
console.error(' ', chalk.bold(phrase))
console.error('')
}

beam.on('remote-address', function ({ host, port }) {
if (!host) console.error('[hyperbeam] Could not detect remote address')
else console.error('[hyperbeam] Joined the DHT - remote address is ' + host + ':' + port)
if (port) console.error('[hyperbeam] Network is holepunchable \\o/')
})

beam.on('connected', function () {
console.error('[hyperbeam] Success! Encrypted tunnel established to remote peer')
})

beam.on('end', () => beam.end())

process.stdin.pipe(beam).pipe(process.stdout)
process.stdin.unref()

process.once('SIGINT', () => {
if (!beam.connected) closeASAP()
else beam.end()
})

function closeASAP () {
console.error('[hyperbeam] Shutting down beam...')

const timeout = setTimeout(() => process.exit(1), 2000)
beam.destroy()
beam.on('close', function () {
clearTimeout(timeout)
})
}
}
}
import Hyperbeam from 'hyperbeam'
import randomWords from 'random-words'
import chalk from 'chalk'
import clipboardy from 'clipboardy'

const FULL_USAGE = `
The beam command is a general-purpose tool for sending data over the network
according to a secret passphrase. You choose a phrase (try to make it hard-ish
to guess!) and then share the phrase with your recipient. The phrase is only
good for 30-60 minutes.

On the sending device:

cat hello.txt | hyp beam "for bob roberts"

On the receiving device:

hyp beam "for bob roberts" > ./hello.txt

This can be really useful for sharing hyper keys between devices. For instance:

> hyp sync ./my-folder
Creating new hyperdrive...
Source: my-folder/
Target: hyper://f7145e1bbc0d17705861e996b47422e0ca50a80db9441249bd721ff426b79f2a/
Begin sync? [y/N] y
Syncing...
Synced
> echo "hyper://f7145e1bbc0d17705861e996b47422e0ca50a80db9441249bd721ff426b79f2a/" \\
| hyp beam "nobody can guess"


You can copy the generated passphrase with the --copy option

`

export default {
name: 'beam',
description: 'Send a stream of data over the network.',
usage: {
simple: '[passphrase]',
full: FULL_USAGE
},
command: async function (args) {
var phrase = args._[0] ? args._.join(' ') : randomWords(3).join(' ')
const beam = new Hyperbeam(phrase)

if (!args._[0]) {
console.error('[hyperbeam] Generated passphrase:\n')
console.error(' ', chalk.bold(phrase))
if (process.argv.indexOf("--copy") != -1){
console.error("Copying passphrase to clipboard")
clipboardy.writeSync(phrase)
}
console.error('')
}

beam.on('remote-address', function ({ host, port }) {
if (!host) console.error('[hyperbeam] Could not detect remote address')
else console.error('[hyperbeam] Joined the DHT - remote address is ' + host + ':' + port)
if (port) console.error('[hyperbeam] Network is holepunchable \\o/')
})

beam.on('connected', function () {
console.error('[hyperbeam] Success! Encrypted tunnel established to remote peer')
})

beam.on('end', () => beam.end())

process.stdin.pipe(beam).pipe(process.stdout)
process.stdin.unref()

process.once('SIGINT', () => {
if (!beam.connected) closeASAP()
else beam.end()
})

function closeASAP () {
console.error('[hyperbeam] Shutting down beam...')

const timeout = setTimeout(() => process.exit(1), 2000)
beam.destroy()
beam.on('close', function () {
clearTimeout(timeout)
})
}
}
}
14 changes: 11 additions & 3 deletions lib/commands/drive/sync.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { join as joinPath } from 'path'
import chokidar from 'chokidar'
import mkdirp from 'mkdirp'
import clipboardy from 'clipboardy'
import dft from 'diff-file-tree'
import chalk from 'chalk'
import debounce from 'p-debounce'
Expand All @@ -14,7 +15,7 @@ import { parseHyperUrl } from '../../urls.js'
const SYNC_INTERVAL = 1000
const FULL_USAGE = `
Options:

--copy - Copy the generated hyper:// URI to your clipboard.
--no-add - Don't include additions to the target location.
--no-overwrite - Don't include overwrites to the target location.
--no-delete - Don't include deletions to the target location.
Expand All @@ -27,7 +28,8 @@ Examples:
hyp drive sync ./local-folder hyper://1234..af/remote-folder --no-delete
hyp drive sync hyper://1234..af/ hyper://fedc..21/
hyp drive sync hyper://1234...af/
hyp drive sync ./local-folder
hyp drive sync ./local-folder
hyp drive sync ./local-folder --copy
`

export default {
Expand Down Expand Up @@ -55,6 +57,12 @@ export default {
console.error(chalk.bold(`Source: ${leftArgs.raw}`))
console.error(chalk.bold(`Target: ${rightArgs.raw}`))

if (process.argv.indexOf("--copy") != -1 && !args._[1]){
console.error("Copied to the url to your clipboard\n")
clipboardy.writeSync(rightArgs.raw)
}


var ok = true

if(!args.yes){
Expand All @@ -63,7 +71,7 @@ export default {
defaultValue: false
})
}

if (!rightArgs.isHyper) mkdirp.sync(rightArgs.path)
if (!ok) process.exit(0)
console.error(live ? 'Live syncing (Ctrl+c to exit)...' : 'Syncing...')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"binary-extensions": "^2.1.0",
"bytes": "^3.1.0",
"chalk": "^1.1.3",
"clipboardy": "^2.3.0",
"chokidar": "^3.4.3",
"concat-stream": "^2.0.0",
"diff-file-tree": "^2.5.1",
Expand Down