Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit ea541ff

Browse files
authored
Merge pull request #128 from microsoft/emimunoz/config
Config commands standardization
2 parents 1939d0b + 596b226 commit ea541ff

File tree

25 files changed

+251
-213
lines changed

25 files changed

+251
-213
lines changed

packages/chatdown/test/commands/chatdown.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ describe('chatdown', () => {
2222
});
2323
});
2424

25-
it('should output an error if no stdin data passed', done => {
26-
cp.exec(`node ./bin/run chatdown`, (error, stdout, stderr) => {
27-
assert(stderr.includes('No input'));
28-
done();
29-
});
30-
});
25+
test
26+
.stdout()
27+
.command(['chatdown'])
28+
.it('should print the help contents when no input is passed', ctx => {
29+
expect(ctx.stdout).to.contain('Converts chat dialog files in <filename>.')
30+
})
3131

3232
it('should throw when a malformed config options is encountered in the input', done => {
3333
cp.exec(`echo bot=LuliBot=joe | node ./bin/run chatdown`, (error, stdout, stderr) => {

packages/command/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
"author": "Microsoft",
66
"bugs": "https://github.com/microsoft/botframework-cli",
77
"dependencies": {
8-
"@oclif/errors": "^1.2.2",
8+
"@oclif/command": "~1.5.13",
9+
"@oclif/config": "~1.12.12",
10+
"@oclif/errors": "~1.2.2",
911
"applicationinsights": "^1.0.8",
10-
"cli-ux": "^4.9.3",
12+
"cli-ux": "~4.9.3",
1113
"chalk": "2.4.1",
1214
"debug": "^4.1.1",
1315
"fs-extra": "^7.0.1"
1416
},
1517
"devDependencies": {
16-
"@oclif/command": "^1.5.13",
17-
"@oclif/config": "^1.12.12",
1818
"@oclif/plugin-help": "^2.1.6",
1919
"@oclif/plugin-plugins": "^1.7.7",
2020
"@oclif/tslint": "^3.1.1",
@@ -30,11 +30,9 @@
3030
"chai": "^4.2.0",
3131
"fancy-test": "^1.4.3",
3232
"mocha": "^6.1.4",
33-
"nock": "^10.0.6",
3433
"nyc": "^13.3.0",
3534
"proxyquire": "^2.1.0",
3635
"rimraf": "^2.6.3",
37-
"sinon": "^7.3.2",
3836
"testdouble": "^3.11.0",
3937
"ts-node": "^8.1.0",
4038
"tslint": "^5.16.0",

packages/command/src/command.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Command as Base } from '@oclif/command'
44
import { CLIError } from '@oclif/errors'
55
export { flags } from '@oclif/command'
66
export { CLIError } from '@oclif/errors'
7-
const chalk = require('chalk')
87
import ReadPipedData from './readpipeddata'
98
import Telemetry from './telemetry'
9+
const chalk = require('chalk')
1010
const pjson = require('../package.json')
1111

1212
export abstract class Command extends Base {
@@ -29,7 +29,7 @@ export abstract class Command extends Base {
2929

3030
warn(input: string | Error): void {
3131
/* tslint:disable:no-console */
32-
console.warn(chalk.yellow(input))
32+
console.error(chalk.yellow(input))
3333
}
3434

3535
async catch(err: any) {
@@ -52,11 +52,11 @@ export abstract class Command extends Base {
5252
process.stdin.destroy()
5353
}
5454

55-
readStdin() {
55+
async readStdin(): Promise<string> {
5656
try {
57-
return ReadPipedData.read()
57+
return await ReadPipedData.read()
5858
} catch (error) {
59-
throw new CLIError(error)
59+
return ''
6060
}
6161
}
6262

packages/command/src/readpipeddata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const ReadPipedStdin = {
22
read: async () => {
3-
return new Promise(async (resolve, reject) => {
3+
return new Promise<string>(async (resolve, reject) => {
44
let input = ''
55
const {stdin} = process
66
stdin.setEncoding('utf8')

packages/command/src/utils.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,27 @@ import {CLIError} from '@oclif/errors'
33

44
const utils = {
55
readTextFile: async (file: any) => {
6-
return new Promise((resolve, reject) => {
6+
return new Promise(async (resolve, reject) => {
77
try {
88
if (!fs.existsSync(file)) {
99
return reject('ENOENT: no such file or directory, ' + file)
1010
}
11-
let fileBuffer = fs.readFileSync(file)
11+
let fileBuffer = await fs.readFile(file)
1212
if (fileBuffer) {
1313
// If the data starts with BOM, we know it is UTF
14-
if (
15-
fileBuffer[0] === 0xEF && fileBuffer[1] === 0xBB && fileBuffer[2] === 0xBF
16-
) {
14+
if (fileBuffer[0] === 0xEF && fileBuffer[1] === 0xBB && fileBuffer[2] === 0xBF) {
1715
// EF BB BF UTF-8 with BOM
1816
fileBuffer = fileBuffer.slice(3)
19-
} else if (
20-
fileBuffer[0] === 0xFF && fileBuffer[1] === 0xFE && fileBuffer[2] === 0x00 && fileBuffer[3] === 0x00
21-
) {
17+
} else if (fileBuffer[0] === 0xFF && fileBuffer[1] === 0xFE && fileBuffer[2] === 0x00 && fileBuffer[3] === 0x00) {
2218
// FF FE 00 00 UTF-32, little-endian BOM
2319
fileBuffer = fileBuffer.slice(4)
24-
} else if (
25-
fileBuffer[0] === 0x00 && fileBuffer[1] === 0x00 && fileBuffer[2] === 0xFE && fileBuffer[3] === 0xFF
26-
) {
20+
} else if (fileBuffer[0] === 0x00 && fileBuffer[1] === 0x00 && fileBuffer[2] === 0xFE && fileBuffer[3] === 0xFF) {
2721
// 00 00 FE FF UTF-32, big-endian BOM
2822
fileBuffer = fileBuffer.slice(4)
29-
} else if (
30-
fileBuffer[0] === 0xFE && fileBuffer[1] === 0xFF && fileBuffer[2] === 0x00 && fileBuffer[3] === 0x00
31-
) {
23+
} else if (fileBuffer[0] === 0xFE && fileBuffer[1] === 0xFF && fileBuffer[2] === 0x00 && fileBuffer[3] === 0x00) {
3224
// FE FF 00 00 UCS-4, unusual octet order BOM (3412)
3325
fileBuffer = fileBuffer.slice(4)
34-
} else if (
35-
fileBuffer[0] === 0x00 && fileBuffer[1] === 0x00 && fileBuffer[2] === 0xFF && fileBuffer[3] === 0xFE
36-
) {
26+
} else if (fileBuffer[0] === 0x00 && fileBuffer[1] === 0x00 && fileBuffer[2] === 0xFF && fileBuffer[3] === 0xFE) {
3727
// 00 00 FF FE UCS-4, unusual octet order BOM (2143)
3828
fileBuffer = fileBuffer.slice(4)
3929
} else if (fileBuffer[0] === 0xFF && fileBuffer[1] === 0xFE) {
@@ -49,8 +39,8 @@ const utils = {
4939
if (err.message.match(/ENOENT: no such file or directory/)) {
5040
return reject(new CLIError(err.message))
5141
}
52-
return reject(
53-
`Invalid Input. Sorry, unable to parse file: \n\n ${JSON.stringify(err, null, 2)}\n\n`)
42+
43+
return reject(`Invalid Input. Sorry, unable to parse file: ${err}`)
5444
}
5545
})
5646
}

packages/command/test/command.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('command', () => {
1919
return Test.run([])
2020
})
2121
.do(output => expect(output.stderr).to.equal('Unknown error during execution. Please file an issue on https://github.com/microsoft/botframework-cli/issues\nfailure\n'))
22-
.it('errors out')
22+
.it('Errors out')
2323

2424
fancy
2525
.stderr()
@@ -66,6 +66,20 @@ describe('command', () => {
6666
.do(output => expect(output.stdout).to.equal('No crash\n'))
6767
.it('Track Event should not crash')
6868

69+
fancy
70+
.stderr()
71+
.do(async () => {
72+
class Test extends Command {
73+
async run() {
74+
let stdin = await this.readStdin()
75+
this.log(stdin)
76+
}
77+
}
78+
return Test.run([])
79+
})
80+
.do(output => expect(output.stderr).to.equal(''))
81+
.it('Command should return empty string if no stdin')
82+
6983
fancy
7084
.stdin('test reading of piped data')
7185
.stdout()

packages/config/README.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ USAGE
3030
<!-- commands -->
3131
* [`bf `](#bf-)
3232
* [`bf config`](#bf-config)
33-
* [`bf config:get [FILE]`](#bf-configget-file)
34-
* [`bf config:qnamaker:set`](#bf-configqnamakerset)
35-
* [`bf config:telemetry`](#bf-configtelemetry)
36-
* [`bf config:telemetry:disable`](#bf-configtelemetrydisable)
37-
* [`bf config:telemetry:enable`](#bf-configtelemetryenable)
33+
* [`bf config:set:qnamaker`](#bf-configsetqnamaker)
34+
* [`bf config:set:telemetry`](#bf-configsettelemetry)
35+
* [`bf config:show`](#bf-configshow)
36+
* [`bf config:show:qnamaker [FILE]`](#bf-configshowqnamaker-file)
37+
* [`bf config:show:telemetry`](#bf-configshowtelemetry)
3838

3939
## `bf `
4040

@@ -64,76 +64,77 @@ OPTIONS
6464

6565
_See code: [src/commands/config/index.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/index.ts)_
6666

67-
## `bf config:get [FILE]`
67+
## `bf config:set:qnamaker`
6868

69-
describe the command here
69+
Set the QnAMaker config data
7070

7171
```
7272
USAGE
73-
$ bf config:get [FILE]
73+
$ bf config:set:qnamaker
7474
7575
OPTIONS
76-
-f, --force
77-
-h, --help show CLI help
78-
-n, --name=name name to print
76+
--kbid=kbid QnAMaker kbid to be set
77+
--subscriptionkey=subscriptionkey QnAMaker subscriptionkey to be set
7978
```
8079

81-
_See code: [src/commands/config/get.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/get.ts)_
80+
_See code: [src/commands/config/set/qnamaker.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/set/qnamaker.ts)_
8281

83-
## `bf config:qnamaker:set`
82+
## `bf config:set:telemetry`
8483

85-
Set the QnAMaker config data
84+
Enable or disable telemetry
8685

8786
```
8887
USAGE
89-
$ bf config:qnamaker:set
88+
$ bf config:set:telemetry
9089
9190
OPTIONS
92-
--kbid=kbid QnAMaker kbid to be set
93-
--subscriptionkey=subscriptionkey QnAMaker subscriptionkey to be set
91+
-d, --disable Disable tlemetry
92+
-h, --help show CLI help
9493
```
9594

96-
_See code: [src/commands/config/qnamaker/set.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/qnamaker/set.ts)_
95+
_See code: [src/commands/config/set/telemetry.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/set/telemetry.ts)_
9796

98-
## `bf config:telemetry`
97+
## `bf config:show`
9998

100-
The telemetry commands allow the user to enable and disable telemetry
99+
Displays the config file
101100

102101
```
103102
USAGE
104-
$ bf config:telemetry
103+
$ bf config:show
105104
106105
OPTIONS
107106
-h, --help show CLI help
108107
```
109108

110-
_See code: [src/commands/config/telemetry/index.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/telemetry/index.ts)_
109+
_See code: [src/commands/config/show.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/show.ts)_
111110

112-
## `bf config:telemetry:disable`
111+
## `bf config:show:qnamaker [FILE]`
113112

114-
Disable telemetry
113+
describe the command here
115114

116115
```
117116
USAGE
118-
$ bf config:telemetry:disable
117+
$ bf config:show:qnamaker [FILE]
119118
120119
OPTIONS
121-
-h, --help show CLI help
120+
-f, --force
121+
-h, --help show CLI help
122+
-n, --name=name name to print
122123
```
123124

124-
_See code: [src/commands/config/telemetry/disable.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/telemetry/disable.ts)_
125+
_See code: [src/commands/config/show/qnamaker.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/show/qnamaker.ts)_
125126

126-
## `bf config:telemetry:enable`
127+
## `bf config:show:telemetry`
127128

128-
Enable Telemetry
129+
Display telemetry settings
129130

130131
```
131132
USAGE
132-
$ bf config:telemetry:enable
133+
$ bf config:show:telemetry
133134
134135
OPTIONS
135136
-h, --help show CLI help
136137
```
137138

138-
_See code: [src/commands/config/telemetry/enable.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/telemetry/enable.ts)_
139+
_See code: [src/commands/config/show/telemetry.ts](https://github.com/microsoft/botframework-cli/blob/v1.0.0/src/commands/config/show/telemetry.ts)_
139140
<!-- commandsstop -->

packages/config/src/commands/config/qnamaker/set.ts renamed to packages/config/src/commands/config/set/qnamaker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {Command, flags} from '@oclif/command'
1+
import {Command, flags} from '@microsoft/bf-cli-command'
22
import {getConfigFile, writeConfigFile, Config} from '../../../utils/configfilehandler'
33

4-
export default class ConfigQnamakerSet extends Command {
4+
export default class ConfigSetQnamaker extends Command {
55
static description = 'Set the QnAMaker config data'
66

77
static flags = {
@@ -10,7 +10,7 @@ export default class ConfigQnamakerSet extends Command {
1010
}
1111

1212
async run() {
13-
const {flags} = this.parse(ConfigQnamakerSet)
13+
const {flags} = this.parse(ConfigSetQnamaker)
1414
let userConfig: Config = await getConfigFile(this.config.configDir)
1515
let qnamaker = userConfig.qnamaker
1616

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Command, flags} from '@microsoft/bf-cli-command'
2+
import {getConfigFile, writeConfigFile, Config} from '../../../utils/configfilehandler'
3+
4+
export default class ConfigSetTelemetry extends Command {
5+
static description = 'Enable or disable telemetry'
6+
7+
static flags = {
8+
help: flags.help({char: 'h'}),
9+
disable: flags.boolean({char: 'd', description: 'Disable tlemetry', default: false})
10+
}
11+
12+
async run() {
13+
const {flags} = this.parse(ConfigSetTelemetry)
14+
let userConfig: Config = await getConfigFile(this.config.configDir)
15+
userConfig.telemetry = !flags.disable
16+
await writeConfigFile(this.config.configDir, userConfig)
17+
this.log('Telemetry set to ' + !flags.disable)
18+
}
19+
}

packages/config/src/commands/config/get.ts renamed to packages/config/src/commands/config/show.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {Command, flags} from '@oclif/command'
1+
import {Command, flags} from '@microsoft/bf-cli-command'
22
import {getConfigFile, Config} from '../../utils/configfilehandler'
33

4-
export default class ConfigGet extends Command {
4+
export default class ConfigShow extends Command {
55
static description = 'Displays the config file'
66

77
static flags = {

0 commit comments

Comments
 (0)