Skip to content

Commit 62da320

Browse files
committed
feat(cli): add --dev flag to target localhost development environment
- Add dev flag to CommonOptions interface - Update createLatitudeClient to check for dev flag - Add --dev flag to all CLI commands (init, pull, push, status, checkout) - When --dev flag is set, CLI connects to localhost:8787 instead of production
1 parent 1978656 commit 62da320

File tree

7 files changed

+29
-4
lines changed

7 files changed

+29
-4
lines changed

packages/cli/src/commands/checkout.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ export function checkout(program: Command): void {
241241
description:
242242
'Create a new version/commit with the specified name and checkout to it',
243243
},
244+
{
245+
flags: '--dev',
246+
description: 'Use localhost development environment',
247+
},
244248
],
245249
action: async (command, versionUuid, options) => {
246250
await command.execute(versionUuid, options)

packages/cli/src/commands/init.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ export function init(program: Command): void {
329329
description: 'Path to initialize the project in',
330330
defaultValue: '.',
331331
},
332+
{
333+
flags: '--dev',
334+
description: 'Use localhost development environment',
335+
},
332336
],
333337
action: async (command, options) => {
334338
await command.execute(options)

packages/cli/src/commands/pull.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ export function pull(program: Command): void {
325325
flags: '-y, --yes',
326326
description: 'Skip confirmation and pull automatically',
327327
},
328+
{
329+
flags: '--dev',
330+
description: 'Use localhost development environment',
331+
},
328332
],
329333
action: async (command, options) => {
330334
await command.execute(options)

packages/cli/src/commands/push.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ export function push(program: Command): void {
300300
flags: '-y, --yes',
301301
description: 'Skip confirmation and push automatically',
302302
},
303+
{
304+
flags: '--dev',
305+
description: 'Use localhost development environment',
306+
},
303307
],
304308
action: async (command, options) => {
305309
await command.execute(options)

packages/cli/src/commands/status.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ export function status(program: Command): void {
258258
description: 'Path to the project',
259259
defaultValue: '.',
260260
},
261+
{
262+
flags: '--dev',
263+
description: 'Use localhost development environment',
264+
},
261265
],
262266
action: async (command, options) => {
263267
await command.execute(options)

packages/cli/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type CommandHandler = (program: Command) => void
1010
*/
1111
export interface CommonOptions {
1212
path: string
13+
dev?: boolean
1314
}
1415

1516
/**

packages/cli/src/utils/baseCommand.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ export abstract class BaseCommand {
3636
*/
3737
abstract execute(...args: any[]): Promise<void>
3838

39-
protected async setClient() {
39+
protected async setClient(options?: CommonOptions) {
4040
if (!this.client) {
4141
this.client = this.createLatitudeClient(
4242
await this.configManager.getApiKey(),
43+
options,
4344
)
4445
}
4546

@@ -57,8 +58,11 @@ export abstract class BaseCommand {
5758
* Creates a Latitude client with the appropriate configuration
5859
* Includes optional config for development environments
5960
*/
60-
protected createLatitudeClient(apiKey: string): Latitude {
61-
if (process.env.NODE_ENV === 'development') {
61+
protected createLatitudeClient(
62+
apiKey: string,
63+
options?: CommonOptions,
64+
): Latitude {
65+
if (process.env.NODE_ENV === 'development' || options?.dev) {
6266
return new Latitude(apiKey, {
6367
__internal: {
6468
gateway: {
@@ -83,7 +87,7 @@ export abstract class BaseCommand {
8387
): Promise<void> {
8488
this.setProjectPath(options)
8589

86-
await this.setClient()
90+
await this.setClient(options)
8791
await this.detectModuleFormat()
8892
await validateEnvironment(
8993
this.projectPath,

0 commit comments

Comments
 (0)