1
1
const Spinnies = require ( 'spinnies' ) ;
2
+ const { getCwd } = require ( '@hubspot/cli-lib/path' ) ;
2
3
const {
3
4
addAccountOptions,
4
5
addConfigOptions,
@@ -19,6 +20,7 @@ const {
19
20
getProjectAppFunctionLogs,
20
21
getLatestProjectAppFunctionLog,
21
22
} = require ( '@hubspot/cli-lib/api/functions' ) ;
23
+ const { getProjectConfig } = require ( '../../lib/projects' ) ;
22
24
const { validateAccount } = require ( '../../lib/validation' ) ;
23
25
const { tailLogs } = require ( '../../lib/serverlessLogs' ) ;
24
26
@@ -120,44 +122,50 @@ exports.describe = 'get logs for a function within a project';
120
122
exports . handler = async options => {
121
123
loadAndValidateOptions ( options ) ;
122
124
123
- const { latest, functionName, projectName, appPath } = options ;
125
+ const { latest, functionName, appPath } = options ;
126
+ let projectName = options . projectName ;
124
127
125
128
if ( ! functionName ) {
126
129
logger . error ( 'You must pass a function name to retrieve logs for.' ) ;
127
- process . exit ( 0 ) ;
130
+ process . exit ( 1 ) ;
128
131
} 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
+ }
133
141
} else if ( ! appPath ) {
134
142
logger . error ( 'You must specify an app path using the --appPath argument.' ) ;
135
- process . exit ( 0 ) ;
143
+ process . exit ( 1 ) ;
136
144
}
137
145
138
146
const accountId = getAccountId ( options ) ;
139
147
140
148
trackCommandUsage ( 'project-logs' , { latest } , accountId ) ;
141
149
142
- appFunctionLog ( accountId , options ) ;
150
+ appFunctionLog ( accountId , { ... options , projectName } ) ;
143
151
} ;
144
152
145
153
exports . builder = yargs => {
146
154
yargs . positional ( 'functionName' , {
147
- describe : 'Serverless function name' ,
155
+ describe : 'Serverless app function name' ,
148
156
type : 'string' ,
157
+ demandOption : true ,
149
158
} ) ;
150
159
yargs
151
160
. options ( {
152
161
appPath : {
153
162
describe : 'path to the app' ,
154
163
type : 'string' ,
155
- hidden : true ,
164
+ demandOption : true ,
156
165
} ,
157
166
projectName : {
158
167
describe : 'name of the project' ,
159
168
type : 'string' ,
160
- hidden : true ,
161
169
} ,
162
170
latest : {
163
171
alias : 'l' ,
0 commit comments