Skip to content

Commit b12ed02

Browse files
committed
fix(deploy): fix conflicting-service error message
1 parent 085eb36 commit b12ed02

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/commands/deploy.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import {
2222
import { EnvironmentVariablesWithAuth } from '../types/generic';
2323
import { fileExists, readFile } from '../utils/fs';
2424
import { CliInfo } from './types';
25-
import { deprecateProjectName, getFullCommand } from './utils';
25+
import {
26+
constructCommandName,
27+
deprecateProjectName,
28+
getFullCommand,
29+
} from './utils';
2630

2731
const log = debug('twilio-run:deploy');
2832

@@ -147,18 +151,24 @@ function handleError(
147151
log('%O', err);
148152
spinner.fail('Failed Deployment');
149153
if (err.name === 'conflicting-servicename') {
154+
const fullCommand = getFullCommand(flags);
150155
const messageBody = stripIndent`
151156
Here are a few ways to solve this problem:
152157
153158
- Rename your project in the package.json "name" property
154159
- Pass an explicit name to your deployment
155-
> ${flags.$0} deploy -n my-new-service-name
160+
> ${constructCommandName(fullCommand, 'deploy', [
161+
'-n',
162+
'my-new-service-name',
163+
])}
156164
- Deploy to the existing service with the name "${(err as any)[
157165
'serviceName'
158166
] || config.serviceName}"
159-
> ${flags.$0} deploy --override-existing-project
167+
> ${constructCommandName(fullCommand, 'deploy', [
168+
'--override-existing-project',
169+
])}
160170
- Run deployment in force mode
161-
> ${flags.$0} deploy --force
171+
> ${constructCommandName(fullCommand, 'deploy', ['--force'])}
162172
`;
163173
console.error(errorMessage(err.message, messageBody));
164174
} else if (err.name === 'HTTPError') {

src/commands/utils.ts

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ import { Arguments } from 'yargs';
55
export const deprecateProjectName = util.deprecate(() => {},
66
'--project-name is deprecated. Please use --service-name instead. If both have been passed --service-name will be preferred.');
77

8+
export function constructCommandName(
9+
fullCommand: string,
10+
action: string,
11+
args: string[] = []
12+
) {
13+
let baseCommand = '';
14+
if (fullCommand.includes(':')) {
15+
baseCommand = fullCommand.substr(0, fullCommand.indexOf(':') + 1);
16+
} else {
17+
baseCommand = fullCommand.split(' ')[0] + ' ';
18+
}
19+
20+
return `${baseCommand}${action} ${args.join(' ')}`;
21+
}
22+
823
export function getFullCommand(flags: Arguments<{}>): string {
924
let baseCommand = flags.$0;
1025
baseCommand = basename(baseCommand);

0 commit comments

Comments
 (0)