Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Applied 'AirBNB JavaScript Style'
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrimue committed Jan 27, 2016
1 parent 6969abd commit 8b86972
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 311 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "airbnb/base",
"rules": {
"no-console": 0,
"no-undef": 0,
"arrow-body-style": 0
}
}
198 changes: 98 additions & 100 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,105 @@
#!/usr/bin/env node
var fs = require('fs'),
colors = require('colors'),
username = require('username'),
autostart = require('./index.js'),
argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.command('enable', 'Enable autostart here with a custom key', function(yargs) {
argv = yargs
.option('n', {
demand: true,
alias: 'name',
describe: 'Name of the key for identifying startup objects',
type: 'string',
nargs: 1
})
.option('c', {
demand: false,
alias: 'command',
describe: 'Command to execute in the path',
type: 'string',
default: 'npm start'
})
.option('p', {
demand: false,
alias: 'path',
describe: 'Place of execution of command',
type: 'string',
default: process.cwd()
})
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;
'use strict';
const autostart = require('./index.js');
let argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.command('enable', 'Enable autostart here with a custom key', (yargs) => {
argv = yargs
.option('n', {
demand: true,
alias: 'name',
describe: 'Name of the key for identifying startup objects',
type: 'string',
nargs: 1,
})
.option('c', {
demand: false,
alias: 'command',
describe: 'Command to execute in the path',
type: 'string',
default: 'npm start',
})
.option('p', {
demand: false,
alias: 'path',
describe: 'Place of execution of command',
type: 'string',
default: process.cwd(),
})
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;

autostart.enableAutostart(argv.n, argv.c, argv.p, function(err) {
if (err) {
console.error('An error occured while trying to enable autostart, here are the details:');
console.error(err);
process.exit(1);
}
autostart.enableAutostart(argv.n, argv.c, argv.p, (err) => {
if (err) {
console.error('An error occured while trying to enable autostart, here are the details:');
console.error(err);
process.exit(1);
}

console.log('Done!');
process.exit(0);
});
})
.command('disable', 'Disable autostart with key', function(yargs) {
argv = yargs
.option('n', {
demand: true,
alias: 'name',
describe: 'Name of the key for identifying startup objecst',
type: 'string',
nargs: 1
})
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;
console.log('Done!');
process.exit(0);
});
})
.command('disable', 'Disable autostart with key', (yargs) => {
argv = yargs
.option('n', {
demand: true,
alias: 'name',
describe: 'Name of the key for identifying startup objecst',
type: 'string',
nargs: 1,
})
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;

autostart.disableAutostart(argv.n, function(err) {
if (err) {
console.error('An error occured while trying to disable autostart, here are the details:');
console.error(err);
process.exit(1);
}
autostart.disableAutostart(argv.n, (err) => {
if (err) {
console.error('An error occured while trying to disable autostart, here are the details:');
console.error(err);
process.exit(1);
}

console.log('Done!');
process.exit(0);
});
})
.command('check', 'Check if autostart is enabled by key', function(yargs) {
argv = yargs
.option('n', {
demand: true,
alias: 'name',
describe: 'Name of the key for identifying startup objects',
type: 'string',
nargs: 1
})
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;
console.log('Done!');
process.exit(0);
});
})
.command('check', 'Check if autostart is enabled by key', (yargs) => {
argv = yargs
.option('n', {
demand: true,
alias: 'name',
describe: 'Name of the key for identifying startup objects',
type: 'string',
nargs: 1,
})
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;

autostart.isAutostartEnabled(argv.n, function(err, isEnabled) {
if (err) {
console.error('An error occured while trying to check if autostart is enabled, here are the details:');
console.error(err);
process.exit(1);
}
autostart.isAutostartEnabled(argv.n, (err, isEnabled) => {
if (err) {
console.error('An error occured, here are the details:');
console.error(err);
process.exit(1);
}

console.log('Done!');
if (isEnabled) {
console.log('Autostart is enabled');
process.exit(0);
} else if (!isEnabled) {
console.log('Autostart is not enabled');
process.exit(0);
}
});
})
.demand(1)
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;
console.log('Done!');
if (isEnabled) {
console.log('Autostart is enabled');
process.exit(0);
} else if (!isEnabled) {
console.log('Autostart is not enabled');
process.exit(0);
}
});
})
.demand(1)
.help('h')
.alias('h', 'help')
.showHelpOnFail(false, 'Use --help for further information')
.argv;
92 changes: 33 additions & 59 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,51 @@
'use strict()';
'use strict';
const osName = process.platform;

var fs = require('fs'),
autostart = require('./lib/' + osName + '.js');

/**
* Enables autostart
* @param {String} key
* @param {String} command
* @param {String} path
* @param {Function} callback
*/
const autostart = require(`./lib/${osName}.js`);

function enableAutostart(key, command, path, callback) {
if (arguments.length < 3) {
throw new Error('Not enough arguments passed to enableAutostart()');
}

else if (typeof(key) !== 'string') {
} else if (typeof(key) !== 'string') {
throw new Error('Passed "key" to enableAutostart() is not a string.');
}

else if (typeof(command) !== 'string') {
} else if (typeof(command) !== 'string') {
throw new Error('Passed "command" to enableAutostart() is not a string.');
}

else if (typeof(path) !== 'string') {
} else if (typeof(path) !== 'string') {
throw new Error('Passed "path" to enableAutostart() is not a string.');
}

if(typeof callback !== 'function') {
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
autostart.enableAutostart(key, command, path, function(error) {
if(!error) resolve();
autostart.enableAutostart(key, command, path, (error) => {
if (!error) resolve();
else reject(error);
});
});
} else {
autostart.enableAutostart(key, command, path, function(error) {
callback(error);
});
}
}

/**
* Disables autostart
* @param {String} key
* @param {Function} callback
*/
return autostart.enableAutostart(key, command, path, (error) => {
callback(error);
});
}

function disableAutostart(key, callback) {
if (arguments.length < 1) {
throw new Error('Not enough arguments passed to disableAutostart()');
}

else if (typeof(key) !== 'string') {
} else if (typeof(key) !== 'string') {
throw new Error('Passed "key" to disableAutostart() is not a string.');
}

if(typeof callback !== 'function') {
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
autostart.disableAutostart(key, function(error) {
if(!error) resolve();
autostart.disableAutostart(key, (error) => {
if (!error) resolve();
else reject(error);
});
});
} else {
autostart.disableAutostart(key, function(error) {
callback(error);
});
}

autostart.disableAutostart(key, (error) => {
callback(error);
});
}

/**
Expand All @@ -81,28 +57,26 @@ function disableAutostart(key, callback) {
function isAutostartEnabled(key, callback) {
if (arguments.length < 1) {
throw new Error('Not enough arguments passed to isAutostartEnabled()');
}

else if (typeof(key) !== 'string') {
} else if (typeof(key) !== 'string') {
throw new Error('Passed "key" to disableAutostart() is not a string.');
}

if(typeof callback !== 'function') {
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
autostart.isAutostartEnabled(key, function(error, isEnabled) {
if(!error) resolve(isEnabled);
else reject(error);
});
});
} else {
autostart.isAutostartEnabled(key, function(error, isEnabled) {
callback(error, isEnabled);
autostart.isAutostartEnabled(key, (error, isEnabled) => {
if (!error) resolve(isEnabled);
else reject(error);
});
});
}

autostart.isAutostartEnabled(key, (error, isEnabled) => {
callback(error, isEnabled);
});
}

module.exports = {
enableAutostart: enableAutostart,
disableAutostart: disableAutostart,
isAutostartEnabled: isAutostartEnabled
enableAutostart,
disableAutostart,
isAutostartEnabled,
};
Loading

0 comments on commit 8b86972

Please sign in to comment.