Skip to content

Commit 8b97064

Browse files
authored
fix: CLI option count type deprecation warning (#257)
1 parent 0994db4 commit 8b97064

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

logs/googleLogs.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class GoogleLogs {
1919
count: {
2020
usage: 'Amount of requested logs',
2121
shortcut: 'c',
22+
type: 'string',
2223
},
2324
},
2425
},

logs/googleLogs.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ describe('GoogleLogs', () => {
5252
expect(googleLogs.commands.logs.options.count).not.toEqual(undefined);
5353
});
5454

55+
it('should have the option "count" with type "string"', () => {
56+
expect(googleLogs.commands.logs.options.count.type).toEqual('string');
57+
});
58+
5559
describe('hooks', () => {
5660
let validateStub;
5761
let setDefaultsStub;

logs/lib/retrieveLogs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
getLogs() {
1414
const project = this.serverless.service.provider.project;
1515
let func = this.options.function;
16-
const pageSize = this.options.count || 10;
16+
const pageSize = parseInt(this.options.count, 10) || 10;
1717

1818
func = getGoogleCloudFunctionName(this.serverless.service.functions, func);
1919

logs/lib/retrieveLogs.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ describe('RetrieveLogs', () => {
9797
});
9898
});
9999

100+
it('should parse the "count" option as an integer', () => {
101+
googleLogs.options.function = 'func1';
102+
googleLogs.options.count = '100';
103+
104+
return googleLogs.getLogs().then(() => {
105+
expect(
106+
requestStub.calledWithExactly('logging', 'entries', 'list', {
107+
filter: 'resource.labels.function_name="full-function-name" AND NOT textPayload=""',
108+
orderBy: 'timestamp desc',
109+
resourceNames: ['projects/my-project'],
110+
pageSize: parseInt(googleLogs.options.count, 10),
111+
})
112+
).toEqual(true);
113+
});
114+
});
115+
100116
it('should throw an error if the function could not be found in the service', () => {
101117
googleLogs.options.function = 'missingFunc';
102118

0 commit comments

Comments
 (0)