mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-09 13:21:58 +00:00
Simpler logging
This commit is contained in:
13
lib/cli.js
13
lib/cli.js
@@ -1,17 +1,18 @@
|
||||
import program from 'commander';
|
||||
import log from 'npmlog';
|
||||
import prompt from 'prompt';
|
||||
import { HOMEBRIDGE_VERSION } from './homebridge';
|
||||
import { User } from './user';
|
||||
import { Server } from './server';
|
||||
import { Provider } from './provider';
|
||||
import { log, setDebugEnabled } from './logger';
|
||||
import { camelCaseToRegularForm } from './util';
|
||||
|
||||
export default function() {
|
||||
|
||||
// Global options (none currently) and version printout
|
||||
program
|
||||
.version(HOMEBRIDGE_VERSION);
|
||||
.version(HOMEBRIDGE_VERSION)
|
||||
.option('-D, --debug', 'turn on debug level logging', () => setDebugEnabled(true));
|
||||
|
||||
// Run the HomeBridge server
|
||||
program
|
||||
@@ -48,13 +49,13 @@ function runServer(options) {
|
||||
this.providerModules = providers.map((provider) => provider.load());
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err.message);
|
||||
log.error(err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function listInstalledProviders(options) {
|
||||
Provider.installed().forEach((provider) => console.log(provider.name));
|
||||
Provider.installed().forEach((provider) => log.info(provider.name));
|
||||
}
|
||||
|
||||
// Encapsulates configuring a provider via the command line.
|
||||
@@ -64,7 +65,7 @@ class CliProviderSetup {
|
||||
// if you didn't specify a provider, print help
|
||||
if (!providerName) {
|
||||
log.error("You must specify the name of the provider to setup. Type 'homebridge providers' to list the providers currently installed.");
|
||||
program.help();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
this.providerName = providerName;
|
||||
@@ -117,7 +118,7 @@ class CliProviderSetup {
|
||||
log.info(`Setup complete.`);
|
||||
}
|
||||
else {
|
||||
log.error(`Setup failed: ${err.message}`);
|
||||
log.error(`Setup failed: ${err.message || err}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user