Skip to content

Commit

Permalink
feat(cli): added verbose option
Browse files Browse the repository at this point in the history
The log level is now set to exclude debug and verbose output by default,
but it can be turned back on by starting room-assistant with the
--verbose option.
  • Loading branch information
mKeRix committed Jan 27, 2020
1 parent 8807e89 commit 09ceab3
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 3 deletions.
39 changes: 39 additions & 0 deletions bin/room-assistant.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
#!/usr/bin/env node
const commandLineUsage = require('command-line-usage');
const commandLineArgs = require('command-line-args');

const optionDefinitions = [
{
name: 'help',
description: 'Display this usage guide.',
alias: 'h',
type: Boolean
},
{
name: 'verbose',
description: 'Turn on debugging output.',
alias: 'v',
type: Boolean
}
];
const usage = commandLineUsage([
{
header: 'room-assistant',
content:
'A companion client for Home Assistant to handle presence detection and sensors in multiple rooms.'
},
{
header: 'Options',
optionList: optionDefinitions
}
]);
const options = commandLineArgs(optionDefinitions);

if (options.help) {
console.log(usage);
return;
}

process.env.NODE_LOG_LEVEL = options.verbose
? 'verbose'
: process.env.NODE_LOG_LEVEL || 'production';

require('../dist/main');
99 changes: 97 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"@nestjs/platform-express": "^6.10.14",
"@nestjs/schedule": "^0.1.1",
"async-mqtt": "^2.4.2",
"command-line-args": "^5.1.1",
"command-line-usage": "^6.1.0",
"config": "^3.2.4",
"democracy": "^3.1.3",
"js-yaml": "^3.13.1",
Expand Down
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule);
const app = await NestFactory.create(AppModule, {
logger:
process.env.NODE_LOG_LEVEL === 'production'
? ['error', 'warn', 'log']
: undefined
});
app.enableShutdownHooks();
await app.listenAsync(6415);
}
Expand Down

0 comments on commit 09ceab3

Please sign in to comment.