Skip to content

Commit c2f4644

Browse files
authored
Merge pull request #585 from HubSpot/improve-project-logs
Improve UX of project logs subcommand
2 parents 512cc5d + bd79581 commit c2f4644

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

packages/cli/commands/project.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
const {
2-
addConfigOptions,
3-
addAccountOptions,
4-
addOverwriteOptions,
5-
} = require('../lib/commonOpts');
1+
const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
62
const deploy = require('./project/deploy');
73
const create = require('./project/create');
84
const upload = require('./project/upload');
@@ -12,7 +8,6 @@ exports.command = 'project';
128
exports.describe = false; //'Commands for working with projects';
139

1410
exports.builder = yargs => {
15-
addOverwriteOptions(yargs, true);
1611
addConfigOptions(yargs, true);
1712
addAccountOptions(yargs, true);
1813

packages/cli/commands/project/logs.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Spinnies = require('spinnies');
2+
const { getCwd } = require('@hubspot/cli-lib/path');
23
const {
34
addAccountOptions,
45
addConfigOptions,
@@ -19,6 +20,7 @@ const {
1920
getProjectAppFunctionLogs,
2021
getLatestProjectAppFunctionLog,
2122
} = require('@hubspot/cli-lib/api/functions');
23+
const { getProjectConfig } = require('../../lib/projects');
2224
const { validateAccount } = require('../../lib/validation');
2325
const { tailLogs } = require('../../lib/serverlessLogs');
2426

@@ -120,44 +122,50 @@ exports.describe = 'get logs for a function within a project';
120122
exports.handler = async options => {
121123
loadAndValidateOptions(options);
122124

123-
const { latest, functionName, projectName, appPath } = options;
125+
const { latest, functionName, appPath } = options;
126+
let projectName = options.projectName;
124127

125128
if (!functionName) {
126129
logger.error('You must pass a function name to retrieve logs for.');
127-
process.exit(0);
130+
process.exit(1);
128131
} else if (!projectName) {
129-
logger.error(
130-
'You must specify a project name using the --projectName argument.'
131-
);
132-
process.exit(0);
132+
const projectConfig = await getProjectConfig(getCwd());
133+
if (projectConfig.name) {
134+
projectName = projectConfig.name;
135+
} else {
136+
logger.error(
137+
'You must specify a project name using the --projectName argument.'
138+
);
139+
process.exit(1);
140+
}
133141
} else if (!appPath) {
134142
logger.error('You must specify an app path using the --appPath argument.');
135-
process.exit(0);
143+
process.exit(1);
136144
}
137145

138146
const accountId = getAccountId(options);
139147

140148
trackCommandUsage('project-logs', { latest }, accountId);
141149

142-
appFunctionLog(accountId, options);
150+
appFunctionLog(accountId, { ...options, projectName });
143151
};
144152

145153
exports.builder = yargs => {
146154
yargs.positional('functionName', {
147-
describe: 'Serverless function name',
155+
describe: 'Serverless app function name',
148156
type: 'string',
157+
demandOption: true,
149158
});
150159
yargs
151160
.options({
152161
appPath: {
153162
describe: 'path to the app',
154163
type: 'string',
155-
hidden: true,
164+
demandOption: true,
156165
},
157166
projectName: {
158167
describe: 'name of the project',
159168
type: 'string',
160-
hidden: true,
161169
},
162170
latest: {
163171
alias: 'l',

0 commit comments

Comments
 (0)