-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbin.js
More file actions
86 lines (73 loc) · 2.13 KB
/
Copy pathbin.js
File metadata and controls
86 lines (73 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
'use strict'
const yargs = require('yargs')
const Shares = require('.')
const pkg = require('./package.json')
const name = pkg.name
const description = pkg.description
yargs.usage(`Usage: ${name} <command> [options]\n\n${description}`)
yargs.options({
machine: {
alias: 'm',
description: 'Machine name (DOCKER_MACHINE_NAME or "default")',
type: 'string'
},
verbose: {
description: 'Verbose output',
type: 'boolean'
}
})
yargs
.global(['machine', 'verbose'])
.group(['machine', 'verbose'], 'Global options:')
yargs
.command('mount', 'Create shared folder and mount it')
.command('unmount', 'Unmount and remove shared folder if it exists')
yargs
.epilogue(`Run '${name} <command> --help' for more information on a command.`)
const verbose = yargs.argv.verbose
const command = yargs.argv._[0]
if (command === 'mount') {
yargs.reset()
.usage(
`Usage: ${name} mount [local path] [guest path]\n\n` +
'Creates a VirtualBox shared folder and mounts it inside the VM. ' +
'Without arguments, the local and guest path would respectively default to:\n' +
'\n- ' + process.cwd() +
'\n- ' + Shares.unixify(process.cwd())
)
.option('name', {
alias: 'n',
description: 'Shared folder name (basename of local path)',
type: 'string'
})
.option('readonly', {
alias: 'r',
description: 'Create read-only shared folder',
type: 'boolean'
})
.option('transient', {
alias: 't',
description: 'Create temporary shared folder',
type: 'boolean'
})
.help()
.example(`${name} mount`, 'Mount the current working directory')
.example(`${name} mount -tr`, 'Read-only and temporary')
.example(`${name} mount . /beep`, 'Mount working directory at /beep')
const opts = yargs.argv
const args = yargs.argv._.slice(1)
opts.hostPath = args[0]
opts.guestPath = args[1]
new Shares({ machine: opts.machine }).mount(opts, bail)
} else {
yargs.showHelp()
}
function bail (err) {
if (err && verbose) {
throw err
} else if (err) {
process.stderr.write(err.message + '.\n')
process.exit(1)
}
}