@hubspot/cli 3.0.10-beta.9 → 3.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +7 -1
  2. package/bin/cli.js +3 -4
  3. package/commands/accounts/list.js +18 -26
  4. package/commands/accounts/rename.js +13 -24
  5. package/commands/accounts.js +4 -1
  6. package/commands/auth.js +33 -16
  7. package/commands/config/set/allowUsageTracking.js +17 -33
  8. package/commands/config/set/defaultAccount.js +24 -34
  9. package/commands/config/set/defaultMode.js +25 -44
  10. package/commands/config/set/httpTimeout.js +10 -28
  11. package/commands/config/set.js +4 -1
  12. package/commands/config.js +4 -1
  13. package/commands/create/api-sample.js +20 -14
  14. package/commands/create/function.js +3 -1
  15. package/commands/create/index.js +0 -1
  16. package/commands/create/module.js +20 -7
  17. package/commands/create/template.js +22 -5
  18. package/commands/create/website-theme.js +12 -1
  19. package/commands/create.js +23 -8
  20. package/commands/customObject/create.js +22 -24
  21. package/commands/customObject/schema/create.js +30 -28
  22. package/commands/customObject/schema/delete.js +20 -20
  23. package/commands/customObject/schema/fetch-all.js +17 -24
  24. package/commands/customObject/schema/fetch.js +29 -24
  25. package/commands/customObject/schema/list.js +8 -17
  26. package/commands/customObject/schema/update.js +31 -29
  27. package/commands/customObject/schema.js +4 -1
  28. package/commands/customObject.js +10 -21
  29. package/commands/fetch.js +15 -30
  30. package/commands/filemanager/fetch.js +13 -25
  31. package/commands/filemanager/upload.js +47 -35
  32. package/commands/filemanager.js +4 -1
  33. package/commands/functions/deploy.js +34 -37
  34. package/commands/functions/list.js +9 -24
  35. package/commands/functions/server.js +13 -29
  36. package/commands/functions.js +4 -1
  37. package/commands/hubdb/clear.js +25 -21
  38. package/commands/hubdb/create.js +25 -22
  39. package/commands/hubdb/delete.js +19 -20
  40. package/commands/hubdb/fetch.js +15 -20
  41. package/commands/hubdb.js +4 -1
  42. package/commands/init.js +25 -13
  43. package/commands/lint.js +14 -23
  44. package/commands/list.js +19 -25
  45. package/commands/logs.js +22 -43
  46. package/commands/mv.js +21 -25
  47. package/commands/open.js +9 -7
  48. package/commands/project/create.js +13 -79
  49. package/commands/project/deploy.js +26 -30
  50. package/commands/project/listBuilds.js +6 -25
  51. package/commands/project/logs.js +81 -81
  52. package/commands/project/upload.js +68 -72
  53. package/commands/project/watch.js +103 -0
  54. package/commands/project.js +2 -0
  55. package/commands/remove.js +12 -20
  56. package/commands/sandbox/create.js +18 -13
  57. package/commands/secrets/addSecret.js +19 -22
  58. package/commands/secrets/deleteSecret.js +18 -21
  59. package/commands/secrets/listSecrets.js +10 -19
  60. package/commands/secrets/updateSecret.js +19 -22
  61. package/commands/secrets.js +4 -1
  62. package/commands/server.js +15 -6
  63. package/commands/{marketplaceValidate/validateTheme.js → theme/marketplace-validate.js} +26 -24
  64. package/commands/theme.js +5 -3
  65. package/commands/upload.js +66 -45
  66. package/commands/watch.js +33 -55
  67. package/lib/commonOpts.js +14 -11
  68. package/lib/enums/exitCodes.js +14 -0
  69. package/lib/links.js +0 -10
  70. package/lib/projects.js +57 -9
  71. package/lib/{createApiSamplePrompt.js → prompts/createApiSamplePrompt.js} +10 -11
  72. package/lib/{createFunctionPrompt.js → prompts/createFunctionPrompt.js} +27 -21
  73. package/lib/{createModulePrompt.js → prompts/createModulePrompt.js} +12 -9
  74. package/lib/prompts/createProjectPrompt.js +68 -0
  75. package/lib/{createTemplatePrompt.js → prompts/createTemplatePrompt.js} +7 -4
  76. package/lib/prompts/folderOverwritePrompt.js +17 -0
  77. package/lib/{prompts.js → prompts/personalAccessKeyPrompt.js} +25 -42
  78. package/lib/prompts/promptUtils.js +10 -0
  79. package/lib/prompts/sandboxesPrompt.js +24 -0
  80. package/lib/prompts/secretPrompt.js +25 -0
  81. package/lib/serverlessLogs.js +3 -2
  82. package/lib/ui.js +48 -0
  83. package/lib/validation.js +4 -3
  84. package/package.json +7 -7
  85. package/commands/app/deploy.js +0 -116
  86. package/commands/app.js +0 -14
  87. package/commands/create/project.js +0 -25
  88. package/lib/prompts/projects.js +0 -40
  89. package/lib/prompts/sandboxes.js +0 -22
  90. package/lib/secretPrompt.js +0 -22
package/commands/open.js CHANGED
@@ -6,17 +6,20 @@ const {
6
6
  } = require('../lib/commonOpts');
7
7
  const { trackCommandUsage } = require('../lib/usageTracking');
8
8
  const { logSiteLinks, getSiteLinksAsArray, openLink } = require('../lib/links');
9
- const inquirer = require('inquirer');
9
+ const { promptUser } = require('../lib/prompts/promptUtils');
10
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
11
+
12
+ const i18nKey = 'cli.commands.open';
10
13
 
11
14
  const separator = ' => ';
12
15
  const createListPrompt = async accountId =>
13
- inquirer.prompt([
16
+ promptUser([
14
17
  {
15
18
  type: 'rawlist',
16
19
  look: false,
17
20
  name: 'open',
18
21
  pageSize: 20,
19
- message: 'Select a link to open',
22
+ message: i18n(`${i18nKey}.selectLink`),
20
23
  choices: getSiteLinksAsArray(accountId).map(
21
24
  l => `${l.shortcut}${separator}${l.url}`
22
25
  ),
@@ -25,8 +28,7 @@ const createListPrompt = async accountId =>
25
28
  ]);
26
29
 
27
30
  exports.command = 'open [shortcut]';
28
- exports.describe =
29
- 'Open a HubSpot page in your browser. Run ‘hs open list’ to see all available shortcuts.';
31
+ exports.describe = i18n(`${i18nKey}.describe`);
30
32
 
31
33
  exports.handler = async options => {
32
34
  const { shortcut, list } = options;
@@ -47,13 +49,13 @@ exports.handler = async options => {
47
49
 
48
50
  exports.builder = yargs => {
49
51
  yargs.positional('[shortcut]', {
50
- describe: "Shortcut of the link you'd like to open",
52
+ describe: i18n(`${i18nKey}.positionals.shortcut.describe`),
51
53
  type: 'string',
52
54
  });
53
55
 
54
56
  yargs.option('list', {
55
57
  alias: 'l',
56
- describe: 'List all supported shortcuts',
58
+ describe: i18n(`${i18nKey}.options.list.describe`),
57
59
  type: 'boolean',
58
60
  });
59
61
 
@@ -1,96 +1,30 @@
1
1
  const {
2
2
  addAccountOptions,
3
3
  addConfigOptions,
4
- setLogLevel,
5
4
  getAccountId,
6
5
  addUseEnvironmentOptions,
7
6
  } = require('../../lib/commonOpts');
8
7
  const { trackCommandUsage } = require('../../lib/usageTracking');
9
- const { logDebugInfo } = require('../../lib/debugInfo');
10
- const {
11
- loadConfig,
12
- validateConfig,
13
- checkAndWarnGitInclusion,
14
- } = require('@hubspot/cli-lib');
15
- const { validateAccount } = require('../../lib/validation');
8
+ const { loadAndValidateOptions } = require('../../lib/validation');
16
9
  const { getCwd } = require('@hubspot/cli-lib/path');
17
10
  const path = require('path');
18
- const { prompt } = require('inquirer');
11
+ const {
12
+ createProjectPrompt,
13
+ } = require('../../lib/prompts/createProjectPrompt');
19
14
  const { createProjectConfig } = require('../../lib/projects');
20
- const { PROJECT_TEMPLATES } = require('@hubspot/cli-lib/lib/constants');
15
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
21
16
 
22
- const loadAndValidateOptions = async options => {
23
- setLogLevel(options);
24
- logDebugInfo(options);
25
- const { config: configPath } = options;
26
- loadConfig(configPath, options);
27
- checkAndWarnGitInclusion();
28
-
29
- if (!(validateConfig() && (await validateAccount(options)))) {
30
- process.exit(1);
31
- }
32
- };
17
+ const i18nKey = 'cli.commands.project.subcommands.create';
33
18
 
34
19
  exports.command = 'create';
35
- exports.describe = false;
20
+ exports.describe = i18n(`${i18nKey}.describe`);
36
21
 
37
22
  exports.handler = async options => {
38
- loadAndValidateOptions(options);
23
+ await loadAndValidateOptions(options);
39
24
 
40
25
  const accountId = getAccountId(options);
41
26
 
42
- const { name, template, location } = await prompt([
43
- {
44
- name: 'name',
45
- message: '[--name] Give your project a name:',
46
- when: !options.name,
47
- validate: input => {
48
- if (!input) {
49
- return 'A project name is required';
50
- }
51
- return true;
52
- },
53
- },
54
- {
55
- name: 'location',
56
- message: '[--location] Where should the project be created?',
57
- when: !options.location,
58
- default: answers => {
59
- return path.resolve(getCwd(), answers.name || options.name);
60
- },
61
- validate: input => {
62
- if (!input) {
63
- return 'A project location is required';
64
- }
65
- return true;
66
- },
67
- },
68
- {
69
- name: 'template',
70
- message: () => {
71
- return options.template &&
72
- !PROJECT_TEMPLATES.find(t => t.name === options.template)
73
- ? `[--template] Could not find template ${options.template}. Please choose an available template.`
74
- : '[--template] Start from a template?';
75
- },
76
- when:
77
- !options.template ||
78
- !PROJECT_TEMPLATES.find(t => t.name === options.template),
79
- type: 'list',
80
- choices: [
81
- {
82
- name: 'No template',
83
- value: 'none',
84
- },
85
- ...PROJECT_TEMPLATES.map(template => {
86
- return {
87
- name: template.label,
88
- value: template.name,
89
- };
90
- }),
91
- ],
92
- },
93
- ]);
27
+ const { name, template, location } = await createProjectPrompt(options);
94
28
 
95
29
  trackCommandUsage('project-create', { projectName: name }, accountId);
96
30
 
@@ -104,20 +38,20 @@ exports.handler = async options => {
104
38
  exports.builder = yargs => {
105
39
  yargs.options({
106
40
  name: {
107
- describe: 'Project name (cannot be changed)',
41
+ describe: i18n(`${i18nKey}.options.name.describe`),
108
42
  type: 'string',
109
43
  },
110
44
  location: {
111
- describe: 'Directory where project should be created',
45
+ describe: i18n(`${i18nKey}.options.location.describe`),
112
46
  type: 'string',
113
47
  },
114
48
  template: {
115
- describe: 'Which template?',
49
+ describe: i18n(`${i18nKey}.options.template.describe`),
116
50
  type: 'string',
117
51
  },
118
52
  });
119
53
 
120
- yargs.example([['$0 project create', 'Create a project']]);
54
+ yargs.example([['$0 project create', i18n(`${i18nKey}.examples.default`)]]);
121
55
 
122
56
  addConfigOptions(yargs, true);
123
57
  addAccountOptions(yargs, true);
@@ -1,47 +1,32 @@
1
1
  const {
2
2
  addAccountOptions,
3
3
  addConfigOptions,
4
- setLogLevel,
5
4
  getAccountId,
6
5
  addUseEnvironmentOptions,
7
6
  } = require('../../lib/commonOpts');
8
7
  const { trackCommandUsage } = require('../../lib/usageTracking');
9
- const { logDebugInfo } = require('../../lib/debugInfo');
10
- const {
11
- loadConfig,
12
- validateConfig,
13
- checkAndWarnGitInclusion,
14
- } = require('@hubspot/cli-lib');
15
8
  const {
16
9
  logApiErrorInstance,
17
10
  ApiErrorContext,
18
11
  } = require('@hubspot/cli-lib/errorHandlers');
19
12
  const { logger } = require('@hubspot/cli-lib/logger');
20
13
  const { deployProject, fetchProject } = require('@hubspot/cli-lib/api/dfs');
21
- const { validateAccount } = require('../../lib/validation');
14
+ const { loadAndValidateOptions } = require('../../lib/validation');
22
15
  const {
23
16
  getProjectConfig,
24
17
  pollDeployStatus,
25
18
  validateProjectConfig,
26
19
  } = require('../../lib/projects');
20
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
27
21
 
28
- const loadAndValidateOptions = async options => {
29
- setLogLevel(options);
30
- logDebugInfo(options);
31
- const { config: configPath } = options;
32
- loadConfig(configPath, options);
33
- checkAndWarnGitInclusion();
34
-
35
- if (!(validateConfig() && (await validateAccount(options)))) {
36
- process.exit(1);
37
- }
38
- };
22
+ const i18nKey = 'cli.commands.project.subcommands.deploy';
23
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
39
24
 
40
25
  exports.command = 'deploy [path]';
41
- exports.describe = false;
26
+ exports.describe = i18n(`${i18nKey}.describe`);
42
27
 
43
28
  exports.handler = async options => {
44
- loadAndValidateOptions(options);
29
+ await loadAndValidateOptions(options);
45
30
 
46
31
  const { path: projectPath, buildId } = options;
47
32
  const accountId = getAccountId(options);
@@ -52,14 +37,21 @@ exports.handler = async options => {
52
37
 
53
38
  validateProjectConfig(projectConfig, projectDir);
54
39
 
55
- logger.debug(`Deploying project at path: ${projectPath}`);
40
+ logger.debug(
41
+ i18n(`${i18nKey}.debug.deploying`, {
42
+ path: projectPath,
43
+ })
44
+ );
45
+
46
+ let exitCode = EXIT_CODES.SUCCESS;
56
47
 
57
48
  const getBuildId = async () => {
58
49
  const { latestBuild } = await fetchProject(accountId, projectConfig.name);
59
50
  if (latestBuild && latestBuild.buildId) {
60
51
  return latestBuild.buildId;
61
52
  }
62
- logger.error('No latest build ID was found.');
53
+ logger.error(i18n(`${i18nKey}.errors.noBuildId`));
54
+ exitCode = EXIT_CODES.ERROR;
63
55
  return;
64
56
  };
65
57
 
@@ -73,7 +65,12 @@ exports.handler = async options => {
73
65
  );
74
66
 
75
67
  if (deployResp.error) {
76
- logger.error(`Deploy error: ${deployResp.error.message}`);
68
+ logger.error(
69
+ i18n(`${i18nKey}.errors.deploy`, {
70
+ details: deployResp.error.message,
71
+ })
72
+ );
73
+ exitCode = EXIT_CODES.ERROR;
77
74
  return;
78
75
  }
79
76
 
@@ -89,27 +86,26 @@ exports.handler = async options => {
89
86
  } else {
90
87
  logApiErrorInstance(e, new ApiErrorContext({ accountId, projectPath }));
91
88
  }
89
+ exitCode = 1;
92
90
  }
91
+ process.exit(exitCode);
93
92
  };
94
93
 
95
94
  exports.builder = yargs => {
96
95
  yargs.positional('path', {
97
- describe: 'Path to a project folder',
96
+ describe: i18n(`${i18nKey}.positionals.path.describe`),
98
97
  type: 'string',
99
98
  });
100
99
 
101
100
  yargs.options({
102
101
  buildId: {
103
- describe: 'Project build ID to be deployed',
102
+ describe: i18n(`${i18nKey}.options.buildId.describe`),
104
103
  type: 'number',
105
104
  },
106
105
  });
107
106
 
108
107
  yargs.example([
109
- [
110
- '$0 project deploy myProjectFolder',
111
- 'Deploy a project within the myProjectFolder folder',
112
- ],
108
+ ['$0 project deploy myProjectFolder', i18n(`${i18nKey}.examples.default`)],
113
109
  ]);
114
110
 
115
111
  addConfigOptions(yargs, true);
@@ -3,17 +3,10 @@ const path = require('path');
3
3
  const {
4
4
  addAccountOptions,
5
5
  addConfigOptions,
6
- setLogLevel,
7
6
  getAccountId,
8
7
  addUseEnvironmentOptions,
9
8
  } = require('../../lib/commonOpts');
10
9
  const { trackCommandUsage } = require('../../lib/usageTracking');
11
- const { logDebugInfo } = require('../../lib/debugInfo');
12
- const {
13
- loadConfig,
14
- validateConfig,
15
- checkAndWarnGitInclusion,
16
- } = require('@hubspot/cli-lib');
17
10
  const {
18
11
  logApiErrorInstance,
19
12
  ApiErrorContext,
@@ -28,33 +21,21 @@ const {
28
21
  getTableHeader,
29
22
  } = require('@hubspot/cli-lib/lib/table');
30
23
  const { getCwd } = require('@hubspot/cli-lib/path');
31
- const { validateAccount } = require('../../lib/validation');
32
- const { link } = require('../../lib/links');
24
+ const { uiLink } = require('../../lib/ui');
25
+ const { loadAndValidateOptions } = require('../../lib/validation');
33
26
  const {
34
27
  getProjectConfig,
35
28
  getProjectDetailUrl,
36
29
  validateProjectConfig,
37
30
  } = require('../../lib/projects');
38
31
  const moment = require('moment');
39
- const { prompt } = require('inquirer');
40
-
41
- const loadAndValidateOptions = async options => {
42
- setLogLevel(options);
43
- logDebugInfo(options);
44
- const { config: configPath } = options;
45
- loadConfig(configPath, options);
46
- checkAndWarnGitInclusion();
47
-
48
- if (!(validateConfig() && (await validateAccount(options)))) {
49
- process.exit(1);
50
- }
51
- };
32
+ const { promptUser } = require('../../lib/prompts/promptUtils');
52
33
 
53
34
  exports.command = 'list-builds [path]';
54
35
  exports.describe = false;
55
36
 
56
37
  exports.handler = async options => {
57
- loadAndValidateOptions(options);
38
+ await loadAndValidateOptions(options);
58
39
 
59
40
  const { path: projectPath, limit } = options;
60
41
  const accountId = getAccountId(options);
@@ -82,7 +63,7 @@ exports.handler = async options => {
82
63
  } else {
83
64
  logger.log(
84
65
  `Showing the ${results.length} most recent builds for ${project.name}. ` +
85
- link(
66
+ uiLink(
86
67
  'View all builds in project details.',
87
68
  getProjectDetailUrl(project.name, accountId)
88
69
  )
@@ -130,7 +111,7 @@ exports.handler = async options => {
130
111
  );
131
112
  }
132
113
  if (paging && paging.next) {
133
- await prompt({
114
+ await promptUser({
134
115
  name: 'more',
135
116
  message: 'Press <enter> to load more, or ctrl+c to exit',
136
117
  });
@@ -3,48 +3,49 @@ const { getCwd } = require('@hubspot/cli-lib/path');
3
3
  const {
4
4
  addAccountOptions,
5
5
  addConfigOptions,
6
- setLogLevel,
7
6
  getAccountId,
8
7
  addUseEnvironmentOptions,
9
8
  } = require('../../lib/commonOpts');
10
9
  const { trackCommandUsage } = require('../../lib/usageTracking');
11
- const { logDebugInfo } = require('../../lib/debugInfo');
12
- const {
13
- loadConfig,
14
- validateConfig,
15
- checkAndWarnGitInclusion,
16
- } = require('@hubspot/cli-lib');
17
10
  const { logger } = require('@hubspot/cli-lib/logger');
18
11
  const { outputLogs } = require('@hubspot/cli-lib/lib/logs');
19
12
  const {
20
13
  getProjectAppFunctionLogs,
21
14
  getLatestProjectAppFunctionLog,
22
15
  } = require('@hubspot/cli-lib/api/functions');
16
+ const {
17
+ getFunctionLogs,
18
+ getLatestFunctionLog,
19
+ } = require('@hubspot/cli-lib/api/results');
23
20
  const { getProjectConfig } = require('../../lib/projects');
24
- const { validateAccount } = require('../../lib/validation');
21
+ const { loadAndValidateOptions } = require('../../lib/validation');
25
22
  const { tailLogs } = require('../../lib/serverlessLogs');
23
+ const { uiAccountDescription } = require('../../lib/ui');
24
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
26
25
 
27
- const loadAndValidateOptions = async options => {
28
- setLogLevel(options);
29
- logDebugInfo(options);
30
- const { config: configPath } = options;
31
- loadConfig(configPath, options);
32
- checkAndWarnGitInclusion();
33
-
34
- if (!(validateConfig() && (await validateAccount(options)))) {
35
- process.exit(1);
36
- }
37
- };
26
+ const i18nKey = 'cli.commands.project.subcommands.logs';
27
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
38
28
 
39
29
  const handleLogsError = (e, accountId, projectName, appPath, functionName) => {
40
30
  if (e.statusCode === 404) {
41
31
  logger.error(
42
- `No logs were found for the function name '${functionName}' in the app path '${appPath}' within the project '${projectName}' in account ${accountId}.`
32
+ appPath
33
+ ? i18n(`${i18nKey}.errors.noAppFunctionLogs`, {
34
+ accountId,
35
+ appPath,
36
+ functionName,
37
+ projectName,
38
+ })
39
+ : i18n(`${i18nKey}.errors.noEndpointLogs`, {
40
+ accountId,
41
+ functionName,
42
+ projectName,
43
+ })
43
44
  );
44
45
  }
45
46
  };
46
47
 
47
- const appFunctionLog = async (accountId, options) => {
48
+ const functionLog = async (accountId, options) => {
48
49
  const {
49
50
  latest,
50
51
  follow,
@@ -56,28 +57,43 @@ const appFunctionLog = async (accountId, options) => {
56
57
 
57
58
  let logsResp;
58
59
 
60
+ const tailCall = async after => {
61
+ try {
62
+ return appPath
63
+ ? getProjectAppFunctionLogs(
64
+ accountId,
65
+ functionName,
66
+ projectName,
67
+ appPath,
68
+ {
69
+ after,
70
+ }
71
+ )
72
+ : getFunctionLogs(accountId, functionName, { after });
73
+ } catch (e) {
74
+ handleLogsError(e, accountId, projectName, appPath, functionName);
75
+ }
76
+ };
77
+ const fetchLatest = async () => {
78
+ return appPath
79
+ ? getLatestProjectAppFunctionLog(
80
+ accountId,
81
+ functionName,
82
+ projectName,
83
+ appPath
84
+ )
85
+ : getLatestFunctionLog(accountId, functionName);
86
+ };
87
+
59
88
  if (follow) {
60
89
  const spinnies = new Spinnies();
61
90
 
62
91
  spinnies.add('tailLogs', {
63
- text: `Waiting for log entries for '${functionName}' on account '${accountId}'.\n`,
92
+ text: i18n(`${i18nKey}.loading`, {
93
+ functionName,
94
+ accountId: uiAccountDescription(accountId),
95
+ }),
64
96
  });
65
- const tailCall = after =>
66
- getProjectAppFunctionLogs(accountId, functionName, projectName, appPath, {
67
- after,
68
- });
69
- const fetchLatest = () => {
70
- try {
71
- return getLatestProjectAppFunctionLog(
72
- accountId,
73
- functionName,
74
- projectName,
75
- appPath
76
- );
77
- } catch (e) {
78
- handleLogsError(e, accountId, projectName, appPath, functionName);
79
- }
80
- };
81
97
 
82
98
  await tailLogs({
83
99
  accountId,
@@ -88,24 +104,13 @@ const appFunctionLog = async (accountId, options) => {
88
104
  });
89
105
  } else if (latest) {
90
106
  try {
91
- logsResp = await getLatestProjectAppFunctionLog(
92
- accountId,
93
- functionName,
94
- projectName,
95
- appPath
96
- );
107
+ logsResp = await fetchLatest();
97
108
  } catch (e) {
98
109
  handleLogsError(e, accountId, projectName, appPath, functionName);
99
110
  }
100
111
  } else {
101
112
  try {
102
- logsResp = await getProjectAppFunctionLogs(
103
- accountId,
104
- functionName,
105
- projectName,
106
- appPath,
107
- {}
108
- );
113
+ logsResp = await tailCall();
109
114
  } catch (e) {
110
115
  handleLogsError(e, accountId, projectName, appPath, functionName);
111
116
  }
@@ -116,74 +121,69 @@ const appFunctionLog = async (accountId, options) => {
116
121
  }
117
122
  };
118
123
 
119
- exports.command = 'logs [functionName]';
120
- exports.describe = 'get logs for a function within a project';
124
+ exports.command = 'logs';
125
+ exports.describe = i18n(`${i18nKey}.describe`);
121
126
 
122
127
  exports.handler = async options => {
123
- loadAndValidateOptions(options);
128
+ await loadAndValidateOptions(options);
124
129
 
125
- const { latest, functionName, appPath } = options;
130
+ const { latest, functionName } = options;
126
131
  let projectName = options.projectName;
127
132
 
128
133
  if (!functionName) {
129
- logger.error('You must pass a function name to retrieve logs for.');
130
- process.exit(1);
134
+ logger.error(i18n(`${i18nKey}.errors.functionNameRequired`));
135
+ process.exit(EXIT_CODES.ERROR);
131
136
  } else if (!projectName) {
132
- const projectConfig = await getProjectConfig(getCwd());
133
- if (projectConfig.name) {
137
+ const { projectConfig } = await getProjectConfig(getCwd());
138
+ if (projectConfig && projectConfig.name) {
134
139
  projectName = projectConfig.name;
135
140
  } else {
136
- logger.error(
137
- 'You must specify a project name using the --projectName argument.'
138
- );
139
- process.exit(1);
141
+ logger.error(i18n(`${i18nKey}.errors.projectNameRequired`));
142
+ process.exit(EXIT_CODES.ERROR);
140
143
  }
141
- } else if (!appPath) {
142
- logger.error('You must specify an app path using the --appPath argument.');
143
- process.exit(1);
144
144
  }
145
145
 
146
146
  const accountId = getAccountId(options);
147
147
 
148
148
  trackCommandUsage('project-logs', { latest }, accountId);
149
149
 
150
- appFunctionLog(accountId, { ...options, projectName });
150
+ functionLog(accountId, { ...options, projectName });
151
151
  };
152
152
 
153
153
  exports.builder = yargs => {
154
- yargs.positional('functionName', {
155
- describe: 'Serverless app function name',
156
- type: 'string',
157
- demandOption: true,
158
- });
159
154
  yargs
160
155
  .options({
161
- appPath: {
162
- describe: 'path to the app',
156
+ functionName: {
157
+ alias: 'function',
158
+ describe: i18n(`${i18nKey}.positionals.functionName.describe`),
163
159
  type: 'string',
164
160
  demandOption: true,
165
161
  },
162
+ appPath: {
163
+ describe: i18n(`${i18nKey}.options.appPath.describe`),
164
+ type: 'string',
165
+ },
166
166
  projectName: {
167
- describe: 'name of the project',
167
+ describe: i18n(`${i18nKey}.options.projectName.describe`),
168
168
  type: 'string',
169
169
  },
170
170
  latest: {
171
171
  alias: 'l',
172
- describe: 'retrieve most recent log only',
172
+ describe: i18n(`${i18nKey}.options.latest.describe`),
173
173
  type: 'boolean',
174
174
  },
175
175
  compact: {
176
- describe: 'output compact logs',
176
+ describe: i18n(`${i18nKey}.options.compact.describe`),
177
177
  type: 'boolean',
178
178
  },
179
179
  follow: {
180
180
  alias: ['t', 'tail', 'f'],
181
- describe: 'follow logs',
181
+ describe: i18n(`${i18nKey}.options.follow.describe`),
182
182
  type: 'boolean',
183
183
  },
184
184
  limit: {
185
185
  alias: ['limit', 'n', 'max-count'],
186
- describe: 'limit the number of logs to output',
186
+ describe: i18n(`${i18nKey}.options.limit.describe`),
187
187
  type: 'number',
188
188
  },
189
189
  })
@@ -191,8 +191,8 @@ exports.builder = yargs => {
191
191
 
192
192
  yargs.example([
193
193
  [
194
- '$0 project logs my-function --appName="app" --projectName="my-project"',
195
- 'Get 5 most recent logs for function named "my-function" within the app named "app" within the project named "my-project"',
194
+ '$0 project logs --function=my-function --appPath="app" --projectName="my-project"',
195
+ i18n(`${i18nKey}.examples.default`),
196
196
  ],
197
197
  ]);
198
198