Skip to content

Commit cf24101

Browse files
authored
feat: testbeats config generation command (#259)
* feat: testbeats config generation command * fix package-lock json * chore: replace inquirer/prompts with prompts * Refactored generate config command to modular functions * Cleanup duplicate and commented code
1 parent d3638c7 commit cf24101

File tree

6 files changed

+527
-6
lines changed

6 files changed

+527
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,5 @@ results
115115
# ignore test/override config files
116116
override-config*.json
117117

118-
.testbeats
118+
.testbeats
119+
.testbeats.json

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"performance-results-parser": "latest",
5454
"phin-retry": "^1.0.3",
5555
"pretty-ms": "^7.0.1",
56+
"prompts": "^2.4.2",
5657
"rosters": "0.0.1",
5758
"sade": "^1.8.1",
5859
"test-results-parser": "0.2.5"

src/cli.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ const sade = require('sade');
55

66
const prog = sade('testbeats');
77
const { PublishCommand } = require('./commands/publish.command');
8+
const { GenerateConfigCommand } = require('./commands/generate-config.command');
89
const logger = require('./utils/logger');
910
const pkg = require('../package.json');
1011

1112
prog
1213
.version(pkg.version)
13-
.option('-c, --config', 'path to config file')
1414
.option('-l, --logLevel', 'Log Level', "INFO")
15+
16+
17+
// Command to publish test results
18+
prog.command('publish')
19+
.option('-c, --config', 'path to config file')
1520
.option('--api-key', 'api key')
1621
.option('--project', 'project name')
1722
.option('--run', 'run name')
@@ -27,9 +32,7 @@ prog
2732
.option('--xunit', 'xunit xml path')
2833
.option('--mstest', 'mstest xml path')
2934
.option('-ci-info', 'ci info extension')
30-
.option('-chart-test-summary', 'chart test summary extension');
31-
32-
prog.command('publish')
35+
.option('-chart-test-summary', 'chart test summary extension')
3336
.action(async (opts) => {
3437
try {
3538
logger.setLevel(opts.logLevel);
@@ -41,4 +44,22 @@ prog.command('publish')
4144
}
4245
});
4346

47+
// Command to initialize and generate TestBeats Configuration file
48+
prog.command('init')
49+
.describe('Generate a TestBeats configuration file')
50+
.example('init')
51+
.action(async (opts) => {
52+
try {
53+
const generate_command = new GenerateConfigCommand(opts);
54+
await generate_command.execute();
55+
} catch (error) {
56+
if (error.name === 'ExitPromptError') {
57+
logger.info('😿 Configuration generation was canceled by the user.');
58+
} else {
59+
throw new Error(`❌ Error in generating configuration file: ${error.message}`)
60+
}
61+
process.exit(1);
62+
}
63+
});
64+
4465
prog.parse(process.argv);

0 commit comments

Comments
 (0)