]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blob - cli/surfer.js
Check for error object
[perso/Immae/Projets/Nodejs/Surfer.git] / cli / surfer.js
1 #!/usr/bin/env node
2
3 'use strict';
4
5 var program = require('commander'),
6 actions = require('./actions');
7
8 // Allow self signed certs!
9 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
10
11 program.version('0.1.0');
12
13 program.command('login <url>')
14 .description('Login to server')
15 .action(actions.login);
16
17 program.command('put <file> [files...]')
18 .option('-d --destination <folder>', 'Destination folder. This is prepended to the relative <file> path')
19 .description('Put a file')
20 .action(actions.put);
21
22 program.command('get [file]')
23 .description('Get a file or directory')
24 .action(actions.get);
25
26 program.command('del')
27 .description('Delete a file')
28 .action(actions.del);
29
30 program.parse(process.argv);
31
32 if (!process.argv.slice(2).length) {
33 program.outputHelp();
34 } else { // https://github.com/tj/commander.js/issues/338
35 var knownCommand = program.commands.some(function (command) { return command._name === process.argv[2]; });
36 if (!knownCommand) {
37 console.error('Unknown command: ' + process.argv[2]);
38 process.exit(1);
39 }
40 }