Skip to content

Commit

Permalink
feat: auto-answer prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbrugger committed Apr 24, 2024
1 parent 8e3949f commit 37b9673
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Options:
-k, --token <string> the authentication token to use (or set env FLATFILE_API_KEY or FLATFILE_BEARER_TOKEN)
-h, --api-url <url> (optional) the API URL to use (or set env FLATFILE_API_URL)
-e, --env <string> (optional) the Environment to use (or set env FLATFILE_ENVIRONMENT_ID)
-y, --yes (optional) skip confirmation prompt
--help display help for command
```

Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { writeErrorToFile } from './shared/utils/error'
import { switchInit } from './switch.init'
import { switchVersion } from './switch.version'
import { createEnvironmentAction } from './x/actions/create.environment.action'
import { deployAction } from './x/actions/deploy.action'
import { deleteAction } from './x/actions/delete.action'
import { deployAction } from './x/actions/deploy.action'
import { developAction } from './x/actions/develop.action'
import { listAgentsAction } from './x/actions/list-agents.action'
import { publishAction } from './x/actions/publish.action'
import { publishPubSub } from './x/actions/publish.pubsub'
import { quickstartAction } from './x/actions/quickstart.action'
import { listAgentsAction } from './x/actions/list-agents.action'

dotenv.config()

Expand Down Expand Up @@ -78,6 +78,10 @@ program
'-e, --env <env-id>',
'(optional) the Environment to use (or set env FLATFILE_ENVIRONMENT_ID)'
)
.option(
'-y, --yes',
'(optional) bypass confirmation prompt and develop immediately'
)
.action(developAction)

program
Expand Down
32 changes: 17 additions & 15 deletions packages/cli/src/x/actions/develop.action.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { Client } from '@flatfile/listener'
import { program } from 'commander'
import { PubSubDriver } from '@flatfile/listener-driver-pubsub'
import { program } from 'commander'
import fs from 'fs'
// @ts-expect-error
import ncc from '@vercel/ncc'
import ora from 'ora'
import path from 'path'
import prompts from 'prompts'

import { apiKeyClient } from './auth.action'
import { getAuth } from '../../shared/get-auth'
import { getEntryFile } from '../../shared/get-entry-file'
import { messages } from '../../shared/messages'
import { apiKeyClient } from './auth.action'

export async function developAction(
file?: string | null | undefined,
options?: Partial<{
apiUrl: string
token: string
env: string
yes: boolean
}>
): Promise<void> {
const outDir = path.posix.join(process.cwd(), '.flatfile')
Expand Down Expand Up @@ -59,20 +60,21 @@ export async function developAction(
})
if (agents?.data && agents?.data?.length > 0) {
console.error(messages.warnDeployedAgents(agents.data))

const { developLocally } = await prompts({
type: 'confirm',
name: 'developLocally',
message: 'Would you like to proceed listening locally? (y/n)',
})

if (!developLocally) {
ora({
text: `Local development aborted`,
}).fail()
process.exit(1)
}

if (!options?.yes) {
const { developLocally } = await prompts({
type: 'confirm',
name: 'developLocally',
message: 'Would you like to proceed listening locally? (y/n)',
})

if (!developLocally) {
ora({
text: `Local development aborted`,
}).fail()
process.exit(1)
}
}
}

const driver = new PubSubDriver(environment.id)
Expand Down

0 comments on commit 37b9673

Please sign in to comment.