Skip to content

Commit

Permalink
use new subcommand with usage and add help texts (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
joehand authored Jan 19, 2017
1 parent 0c0fb13 commit 585ffa0
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 35 deletions.
20 changes: 11 additions & 9 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ process.title = 'dat-next'

var config = {
defaults: [
{ name: 'dir', default: process.cwd() },
{ name: 'dir', default: process.cwd(), help: 'set the directory for Dat' },
{ name: 'logspeed', default: 200 },
{ name: 'port', default: 3282 },
{ name: 'utp', default: true, boolean: true },
{ name: 'debug', default: process.env.DEBUG },
{ name: 'port', default: 3282, help: 'port to use for connections' },
{ name: 'utp', default: true, boolean: true, help: 'use utp for discovery' },
{ name: 'debug', default: process.env.DEBUG }, // TODO: does not work right now
{ name: 'quiet', default: false, boolean: true },
{ name: 'verbose', default: false, boolean: true, abbr: 'v' },
{ name: 'server', default: 'https://dat.land/api/v1' }
],
root: {
Expand All @@ -40,12 +39,15 @@ var config = {
require('../lib/commands/auth/register'),
require('../lib/commands/auth/whoami'),
require('../lib/commands/auth/logout'),
require('../lib/commands/auth/login'),
{
require('../lib/commands/auth/login')
],
usage: {
command: usage,
option: {
name: 'help',
command: usage
abbr: 'h'
}
],
},
aliases: {
'init': 'create'
}
Expand Down
14 changes: 13 additions & 1 deletion lib/commands/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ var debug = require('debug')('dat')
module.exports = {
name: 'clone',
command: clone,
help: [
'Clone a remote Dat archive',
'',
'Usage: dat clone <link> [download-folder]'
].join('\n'),
options: [
{
name: 'temp',
boolean: true,
default: false
default: false,
help: 'use an in-memory database for metadata'
},
{
name: 'upload',
boolean: true,
default: false,
help: 'upload data to other peers while cloning'
}
]
}
Expand Down
8 changes: 7 additions & 1 deletion lib/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ var debug = require('debug')('dat')
module.exports = {
name: 'create',
command: create,
help: [
'Create a local Dat archive to share',
'',
'Usage: dat create [directory]'
].join('\n'),
options: [
{
name: 'import',
boolean: true,
default: true
default: true,
help: 'Import files in the given directory'
},
{
name: 'ignoreHidden',
Expand Down
7 changes: 7 additions & 0 deletions lib/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ var doctor = require('dat-doctor')

module.exports = {
name: 'doctor',
help: [
'Call the Doctor! Runs two tests:',
' 1. Check if you can connect to a peer on a public server.',
' 2. Gives you a link to test direct peer connections.',
'',
'Usage: dat doctor [<link>]'
].join('\n'),
options: [],
command: function (opts) {
opts.id = opts._[0]
Expand Down
14 changes: 13 additions & 1 deletion lib/commands/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ var debug = require('debug')('dat')

module.exports = {
name: 'pull',
options: [],
help: [
'Pull updates from a cloned Dat archive',
'',
'Usage: dat pull'
].join('\n'),
options: [
{
name: 'upload',
boolean: true,
default: false,
help: 'upload data to other peers while pulling'
}
],
command: function (opts) {
// Force these options for pull command
opts.resume = true
Expand Down
5 changes: 5 additions & 0 deletions lib/commands/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ var debug = require('debug')('dat')

module.exports = {
name: 'snapshot',
help: [
'Create a snapshot Dat archive',
'',
'Usage: dat snapshot'
].join('\n'),
options: [],
command: function snapshot (opts) {
// Force these options for snapshot command
Expand Down
12 changes: 10 additions & 2 deletions lib/commands/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ var debug = require('debug')('dat')

module.exports = {
name: 'sync',
help: [
'Sync a Dat archive with the network',
'Watch and import file changes (if you created the archive)',
'',
'Usage: dat sync'
].join('\n'),
options: [
{
name: 'import',
boolean: true,
default: true
default: true,
help: 'Import files from the directory to the database.'
},
{
name: 'ignoreHidden',
Expand All @@ -21,7 +28,8 @@ module.exports = {
{
name: 'watch',
boolean: true,
default: true
default: true,
help: 'Watch for changes and import updated files.'
}
],
command: function (opts) {
Expand Down
38 changes: 18 additions & 20 deletions lib/usage.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
module.exports = function (opts) {
module.exports = function (opts, help, usage) {
if (opts.version) {
var pkg = require('../package.json')
console.error(pkg.version)
process.exit(1)
}
console.error('Usage: dat <cmd> [options]')
console.error(' dat create create a local archive')
console.error(' dat snapshot create a local snapshot archive')
console.error(' dat clone <dat-link> <directory> clone a remote archive')
console.error('')
console.error(' dat sync sync files with the network')
console.error(' dat pull update from remote archive & exit')
console.error('Sharing Files:')
console.error(' dat create [<dir>] create a local archive')
console.error(' dat snapshot create a local snapshot archive')
console.error(' dat sync watch for changes & sync files with the network')
console.error('')
console.error(' --dir=<folder> set directory')
console.error(' --no-import do not import files (create, sync)')
console.error(' --quiet only print out the dat link')
console.error(' --port=3282 set the port for discovery')
console.error(' --no-utp do not use utp for network connections')
console.error('Downloading Files:')
console.error(' dat clone <link> [<dir>] clone a remote archive')
console.error(' dat pull update from remote archive & exit')
console.error(' dat sync sync files with the network')
console.error('')
console.error(' dat register register for an account')
console.error(' dat login login to an account')
console.error(' dat logout logout from the server')
console.error(' dat whoami get login information')
console.error(' dat publish publish dataset to registry')
console.error('')
console.error(' dat --version, -v get your dat version')
console.error(' dat help print this usage guide')
console.error(' dat doctor run the dat network doctor')
console.error('Help & Troubleshooting:')
console.error(' dat doctor run the dat network doctor')
console.error(' dat [<command>] --help, -h print help for a command')
console.error(' dat --version, -v print your dat version')
console.error('')
if (usage) {
console.error('General Options:')
console.error(usage)
}
console.error('Have fun using Dat! Learn more at docs.datproject.org')
process.exit(1)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prompt": "^1.0.0",
"rimraf": "^2.5.4",
"status-logger": "^3.0.0",
"subcommand": "^2.0.4",
"subcommand": "^2.1.0",
"township-client": "^1.3.1",
"xtend": "^4.0.1"
},
Expand Down

0 comments on commit 585ffa0

Please sign in to comment.