Skip to content
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
40 changes: 40 additions & 0 deletions packages/twilio-run/__tests__/config/logs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getConfigFromFlags, LogsCliFlags } from '../../src/config/logs';

const baseFlags = {
$0: 'twilio-run',
_: ['logs'],
serviceSid: 'ZS11112222111122221111222211112222',
} as LogsCliFlags;

describe('getConfigFromFlags', () => {
test('should return a config', async () => {
const flags = { ...baseFlags };
const config = await getConfigFromFlags(flags);
expect(config).toBeDefined();
expect(config.serviceSid).toBe(baseFlags.serviceSid);
});

test('should set environment to "dev" by default', async () => {
const flags = { ...baseFlags };
const config = await getConfigFromFlags(flags);
expect(config.environment).toBe('dev');
});

test('should set environment with a flag', async () => {
const flags = { ...baseFlags, environment: 'stage' };
const config = await getConfigFromFlags(flags);
expect(config.environment).toBe('stage');
});

test('should set environment to empty string with "production" flag', async () => {
const flags = { ...baseFlags, production: true };
const config = await getConfigFromFlags(flags);
expect(config.environment).toBe('');
});

test('production overrides setting environment directly', async () => {
const flags = { ...baseFlags, production: true, environment: 'stage' };
const config = await getConfigFromFlags(flags);
expect(config.environment).toBe('');
});
});
10 changes: 8 additions & 2 deletions packages/twilio-run/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ export const cliInfo: CliInfo = {
'tail',
'output-format',
'log-cache-size',
'production',
]),
environment: {
...ALL_FLAGS['environment'],
describe: 'The environment to retrieve the logs for',
default: 'dev',
},
production: {
...ALL_FLAGS['production'],
describe:
'Retrieve logs for the production environment. Overrides the "environment" flag',
},
},
};

Expand All @@ -110,8 +116,8 @@ function optionBuilder(yargs: Argv<any>): Argv<LogsCliFlags> {
'Prints the last 50 logs for the current project in the dev environment'
)
.example(
'$0 logs --environment=production',
'Prints the last 50 logs for the current project in the production environment'
'$0 logs --environment=stage',
'Prints the last 50 logs for the current project in the stage environment'
)
.example(
'$0 logs --tail',
Expand Down
5 changes: 5 additions & 0 deletions packages/twilio-run/src/config/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type ConfigurableLogsCliFlags = Pick<
| 'tail'
| 'outputFormat'
| 'logCacheSize'
| 'production'
>;
export type LogsCliFlags = Arguments<ConfigurableLogsCliFlags>;

Expand All @@ -60,6 +61,10 @@ export async function getConfigFromFlags(
cwd = flags.cwd || cwd;
environment = flags.environment || environment;

if (flags.production) {
environment = '';
}

const { localEnv: envFileVars, envPath } = await readLocalEnvFile(flags);
const { username, password } = await getCredentialsFromFlags(
flags,
Expand Down