Skip to content

Commit 4c0568c

Browse files
committed
set env vars when creating project; add (bypassable) prompt when deleting project
1 parent 2f6d581 commit 4c0568c

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "disco",
33
"description": "deploy and manage your web projects",
4-
"version": "0.5.44",
4+
"version": "0.5.45",
55
"author": "The Disco Team",
66
"bin": {
77
"disco": "./bin/run.js"

src/commands/env/set.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class EnvSet extends Command {
3636
const body: EnvVarRequestBody = {
3737
envVariables: [],
3838
}
39+
// de-dupe this code as it also exists in projects:add
3940
for (const variable of argv) {
4041
const parts = (variable as string).split('=')
4142
const varName = parts[0]

src/commands/projects/add.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
import {Command, Flags} from '@oclif/core'
1+
import {Args, Command, Flags} from '@oclif/core'
22
import {getDisco} from '../../config.js'
33
import {request, readEventSource} from '../../auth-request.js'
44

55
export default class ProjectsAdd extends Command {
6-
static description = 'add a project'
6+
static override args = {
7+
variables: Args.string({description: 'environment variables to set'}),
8+
}
9+
10+
// set to be able to receive variable number of arguments
11+
static strict = false
12+
13+
static description = `add a project to an existing disco instance
714
8-
static examples = ['<%= config.bin %> <%= command.id %>']
15+
this will deploy the project. from that point on, every "git push" to the project's repo will automatically trigger a new deployment.
16+
17+
for most projects, you will need to pass a name, a domain name and a github repo. you can optionally pass environment variables as well.`
18+
19+
static examples = [
20+
'<%= config.bin %> <%= command.id %> --name myblog --domain blog.example.com --github myuser/myblog',
21+
'<%= config.bin %> <%= command.id %> --name myblog --domain blog.example.com --github myuser/myblog API_KEY=09asf07gaq0 OTHER_ENV_VAR=true',
22+
]
923

1024
static flags = {
1125
name: Flags.string({required: true, description: 'project name'}),
@@ -31,7 +45,7 @@ export default class ProjectsAdd extends Command {
3145
}
3246

3347
public async run(): Promise<void> {
34-
const {flags} = await this.parse(ProjectsAdd)
48+
const {argv, flags} = await this.parse(ProjectsAdd)
3549

3650
if (flags.github !== undefined && !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(flags.github)) {
3751
this.error('Invalid Github repository format, expected "user/repo"')
@@ -48,11 +62,14 @@ or edit your GitHub repo permissions by running "disco github:apps:manage <your
4862

4963
const url = `https://${discoConfig.host}/api/projects`
5064

65+
const envVariables = extractEnvVars(argv as string[])
66+
5167
const body = {
5268
name: flags.name,
5369
githubRepo: flags.github,
5470
domain: flags.domain,
5571
branch: flags.branch,
72+
envVariables,
5673
}
5774

5875
const res = await request({method: 'POST', url, discoConfig, body, expectedStatuses: [201]})
@@ -74,6 +91,26 @@ or edit your GitHub repo permissions by running "disco github:apps:manage <your
7491
}
7592
}
7693

94+
// based on code in env/set.ts
95+
function extractEnvVars(argv: string[]): {name: string; value: string}[] {
96+
const envVars: {name: string; value: string}[] = []
97+
for (const variable of argv) {
98+
const parts = (variable as string).split('=')
99+
const name = parts[0]
100+
let value = parts.slice(1).join('=')
101+
if (value[0] === value.slice(-1) && ['"', "'"].includes(value[0])) {
102+
value = value.slice(1, -1)
103+
}
104+
105+
envVars.push({
106+
name,
107+
value,
108+
})
109+
}
110+
111+
return envVars
112+
}
113+
77114
async function isGithubRepoAuthorized(discoConfig: any, repoBeingChecked: string) {
78115
// check if the user has access to the github repo
79116
const url = `https://${discoConfig.host}/api/github-app-repos`

src/commands/projects/remove.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Args, Command, Flags} from '@oclif/core'
22
import {getDisco} from '../../config.js'
33
import {request} from '../../auth-request.js'
4+
import {confirm} from '@inquirer/prompts'
45

56
export default class ProjectsRemove extends Command {
67
static args = {
@@ -12,6 +13,7 @@ export default class ProjectsRemove extends Command {
1213
static examples = ['<%= config.bin %> <%= command.id %> project-name']
1314

1415
static flags = {
16+
'no-input': Flags.boolean({default: false, description: 'do not ask for confirmation'}),
1517
disco: Flags.string({required: false}),
1618
}
1719

@@ -20,6 +22,17 @@ export default class ProjectsRemove extends Command {
2022

2123
const discoConfig = getDisco(flags.disco || null)
2224

25+
if (!flags['no-input']) {
26+
const response = await confirm({
27+
message: `Are you sure you want to remove the project "${args.project}"? This action cannot be undone.`,
28+
default: false,
29+
})
30+
if (!response) {
31+
this.log('Not doing anything.')
32+
return
33+
}
34+
}
35+
2336
const url = `https://${discoConfig.host}/api/projects/${args.project}`
2437
try {
2538
await request({method: 'DELETE', url, discoConfig, expectedStatuses: [200, 204]})

tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"root":["./src/auth-request.ts","./src/config.ts","./src/index.ts","./src/commands/deploy.ts","./src/commands/init.ts","./src/commands/logs.ts","./src/commands/run.ts","./src/commands/apikeys/list.ts","./src/commands/apikeys/remove.ts","./src/commands/deploy/cancel.ts","./src/commands/deploy/list.ts","./src/commands/deploy/output.ts","./src/commands/discos/list.ts","./src/commands/domains/add.ts","./src/commands/domains/list.ts","./src/commands/domains/remove.ts","./src/commands/env/get.ts","./src/commands/env/list.ts","./src/commands/env/remove.ts","./src/commands/env/set.ts","./src/commands/github/apps/add.ts","./src/commands/github/apps/list.ts","./src/commands/github/apps/manage.ts","./src/commands/github/apps/prune.ts","./src/commands/github/repos/list.ts","./src/commands/invite/accept.ts","./src/commands/invite/create.ts","./src/commands/meta/host.ts","./src/commands/meta/info.ts","./src/commands/meta/stats.ts","./src/commands/meta/upgrade.ts","./src/commands/nodes/add.ts","./src/commands/nodes/list.ts","./src/commands/nodes/remove.ts","./src/commands/postgres/create.ts","./src/commands/postgres/tunnel.ts","./src/commands/postgres/addon/install.ts","./src/commands/postgres/addon/remove.ts","./src/commands/postgres/addon/update.ts","./src/commands/postgres/databases/add.ts","./src/commands/postgres/databases/attach.ts","./src/commands/postgres/databases/detach.ts","./src/commands/postgres/databases/list.ts","./src/commands/postgres/databases/remove.ts","./src/commands/postgres/instances/add.ts","./src/commands/postgres/instances/list.ts","./src/commands/postgres/instances/remove.ts","./src/commands/projects/add.ts","./src/commands/projects/list.ts","./src/commands/projects/move.ts","./src/commands/projects/remove.ts","./src/commands/registry/addon/install.ts","./src/commands/registry/addon/remove.ts","./src/commands/registry/addon/update.ts","./src/commands/scale/get.ts","./src/commands/scale/set.ts","./src/commands/syslog/add.ts","./src/commands/syslog/list.ts","./src/commands/syslog/remove.ts","./src/commands/volumes/export.ts","./src/commands/volumes/import.ts","./src/commands/volumes/list.ts"],"errors":true,"version":"5.8.2"}
1+
{"root":["./src/auth-request.ts","./src/config.ts","./src/index.ts","./src/commands/deploy.ts","./src/commands/init.ts","./src/commands/logs.ts","./src/commands/run.ts","./src/commands/apikeys/list.ts","./src/commands/apikeys/remove.ts","./src/commands/deploy/cancel.ts","./src/commands/deploy/list.ts","./src/commands/deploy/output.ts","./src/commands/discos/list.ts","./src/commands/domains/add.ts","./src/commands/domains/list.ts","./src/commands/domains/remove.ts","./src/commands/env/get.ts","./src/commands/env/list.ts","./src/commands/env/remove.ts","./src/commands/env/set.ts","./src/commands/github/apps/add.ts","./src/commands/github/apps/list.ts","./src/commands/github/apps/manage.ts","./src/commands/github/apps/prune.ts","./src/commands/github/repos/list.ts","./src/commands/invite/accept.ts","./src/commands/invite/create.ts","./src/commands/meta/host.ts","./src/commands/meta/info.ts","./src/commands/meta/stats.ts","./src/commands/meta/upgrade.ts","./src/commands/nodes/add.ts","./src/commands/nodes/list.ts","./src/commands/nodes/remove.ts","./src/commands/postgres/create.ts","./src/commands/postgres/tunnel.ts","./src/commands/postgres/addon/install.ts","./src/commands/postgres/addon/remove.ts","./src/commands/postgres/addon/update.ts","./src/commands/postgres/databases/add.ts","./src/commands/postgres/databases/attach.ts","./src/commands/postgres/databases/detach.ts","./src/commands/postgres/databases/list.ts","./src/commands/postgres/databases/remove.ts","./src/commands/postgres/instances/add.ts","./src/commands/postgres/instances/list.ts","./src/commands/postgres/instances/remove.ts","./src/commands/projects/add.ts","./src/commands/projects/list.ts","./src/commands/projects/move.ts","./src/commands/projects/remove.ts","./src/commands/registry/addon/install.ts","./src/commands/registry/addon/remove.ts","./src/commands/registry/addon/update.ts","./src/commands/scale/get.ts","./src/commands/scale/set.ts","./src/commands/syslog/add.ts","./src/commands/syslog/list.ts","./src/commands/syslog/remove.ts","./src/commands/volumes/export.ts","./src/commands/volumes/import.ts","./src/commands/volumes/list.ts"],"version":"5.8.2"}

0 commit comments

Comments
 (0)