Skip to content

Commit

Permalink
Don't require user config if not really needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Aug 27, 2024
1 parent aa331ee commit 7ad5182
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-garlics-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@e2b/cli": patch
---

Fix config bug in template build
11 changes: 7 additions & 4 deletions packages/cli/src/commands/template/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as stripAnsi from 'strip-ansi'
import * as boxen from 'boxen'
import commandExists from 'command-exists'
import { wait } from 'src/utils/wait'
import { ensureAccessToken, ensureUserConfig } from 'src/api'
import { ensureAccessToken } from 'src/api'
import { getRoot } from 'src/utils/filesystem'
import {
asBold,
Expand All @@ -28,6 +28,7 @@ import { configName, getConfigPath, loadConfig, saveConfig } from 'src/config'
import * as child_process from 'child_process'

import { client } from 'src/api'
import { getUserConfig } from 'src/user'

const templateCheckInterval = 500 // 0.5 sec

Expand Down Expand Up @@ -138,8 +139,6 @@ export const buildCommand = new commander.Command('build')
}

const accessToken = ensureAccessToken()
const userConfig = ensureUserConfig()

process.stdout.write('\n')

const newName = opts.name?.trim()
Expand Down Expand Up @@ -186,7 +185,11 @@ export const buildCommand = new commander.Command('build')
memoryMB = opts.memoryMb || config.memory_mb
teamID = opts.team || config.team_id
}
teamID = teamID || userConfig.teamId

const userConfig = getUserConfig()
if (userConfig) {
teamID = teamID || userConfig.teamId
}

if (config && templateID && config.template_id !== templateID) {
// error: you can't specify different ID than the one in config
Expand Down
13 changes: 10 additions & 3 deletions packages/cli/src/commands/template/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chalk from 'chalk'
import * as e2b from 'e2b'
import * as fs from 'fs'

import { ensureAccessToken, ensureUserConfig } from 'src/api'
import { ensureAccessToken } from 'src/api'

import {
asBold,
Expand All @@ -25,6 +25,7 @@ import { listSandboxTemplates } from './list'
import { getPromptTemplates } from 'src/utils/templatePrompt'
import { confirm } from 'src/utils/confirm'
import { client } from 'src/api'
import { getUserConfig } from 'src/user'

const deleteTemplate = e2b.withAccessToken(
client.api.path('/templates/{templateID}').method('delete').create(),
Expand Down Expand Up @@ -58,7 +59,8 @@ export const deleteCommand = new commander.Command('delete')
},
) => {
try {
const userConfig = ensureUserConfig()
let teamId = opts.team

const accessToken = ensureAccessToken()
const root = getRoot(opts.path)

Expand All @@ -71,9 +73,14 @@ export const deleteCommand = new commander.Command('delete')
template_id: template,
})
} else if (opts.select) {
const userConfig = getUserConfig()
if (userConfig) {
teamId = teamId || userConfig.teamId || userConfig.defaultTeamId! // default team ID is here for backwards compatibility
}

const allTemplates = await listSandboxTemplates({
accessToken: accessToken,
teamID: opts.team || userConfig.teamId || userConfig.defaultTeamId! // default team ID is here for backwards compatibility
teamID: teamId,
})
const selectedTemplates = await getPromptTemplates(
allTemplates,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/template/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const listCommand = new commander.Command('list')

export async function listSandboxTemplates({
accessToken, teamID
}: { accessToken: string, teamID: string }): Promise<e2b.components['schemas']['Template'][]> {
}: { accessToken: string, teamID?: string }): Promise<e2b.components['schemas']['Template'][]> {
const templates = await listTemplates(accessToken, {teamID})
return templates.data
}

0 comments on commit 7ad5182

Please sign in to comment.