Skip to content

Improve UX of project logs subcommand #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/cli/commands/project.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const {
addConfigOptions,
addAccountOptions,
addOverwriteOptions,
} = require('../lib/commonOpts');
const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
const deploy = require('./project/deploy');
const create = require('./project/create');
const upload = require('./project/upload');
Expand All @@ -12,7 +8,6 @@ exports.command = 'project';
exports.describe = false; //'Commands for working with projects';

exports.builder = yargs => {
addOverwriteOptions(yargs, true);
addConfigOptions(yargs, true);
addAccountOptions(yargs, true);

Expand Down
30 changes: 19 additions & 11 deletions packages/cli/commands/project/logs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Spinnies = require('spinnies');
const { getCwd } = require('@hubspot/cli-lib/path');
const {
addAccountOptions,
addConfigOptions,
Expand All @@ -19,6 +20,7 @@ const {
getProjectAppFunctionLogs,
getLatestProjectAppFunctionLog,
} = require('@hubspot/cli-lib/api/functions');
const { getProjectConfig } = require('../../lib/projects');
const { validateAccount } = require('../../lib/validation');
const { tailLogs } = require('../../lib/serverlessLogs');

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

const { latest, functionName, projectName, appPath } = options;
const { latest, functionName, appPath } = options;
let projectName = options.projectName;

if (!functionName) {
logger.error('You must pass a function name to retrieve logs for.');
process.exit(0);
process.exit(1);
} else if (!projectName) {
logger.error(
'You must specify a project name using the --projectName argument.'
);
process.exit(0);
const projectConfig = await getProjectConfig(getCwd());
if (projectConfig.name) {
projectName = projectConfig.name;
} else {
logger.error(
'You must specify a project name using the --projectName argument.'
);
process.exit(1);
}
} else if (!appPath) {
logger.error('You must specify an app path using the --appPath argument.');
process.exit(0);
process.exit(1);
}

const accountId = getAccountId(options);

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

appFunctionLog(accountId, options);
appFunctionLog(accountId, { ...options, projectName });
};

exports.builder = yargs => {
yargs.positional('functionName', {
describe: 'Serverless function name',
describe: 'Serverless app function name',
type: 'string',
demandOption: true,
});
yargs
.options({
appPath: {
describe: 'path to the app',
type: 'string',
hidden: true,
demandOption: true,
},
projectName: {
describe: 'name of the project',
type: 'string',
hidden: true,
},
latest: {
alias: 'l',
Expand Down