Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add alias/name handling to CLI

Tomas Valenta2891479571cc
diff --git a/packages/cli/src/commands/template/build.ts b/packages/cli/src/commands/template/build.ts
index b852d3ff0..95c84d6a2 100644
--- a/packages/cli/src/commands/template/build.ts
+++ b/packages/cli/src/commands/template/build.ts
@@ -52,6 +52,10 @@ export const buildCommand = new commander.Command('build')
defaultDockerfileName,
)} or ${asLocal(fallbackDockerfileName)} in root directory`,
)
+ .option(
+ '-n, --name <name>',
+ 'Specify name of sandbox template. You can use the name to start the sandbox in the SDK',
+ )
.alias('bd')
.action(
async (
@@ -59,6 +63,7 @@ export const buildCommand = new commander.Command('build')
opts: {
path?: string;
dockerfile?: string;
+ name?: string;
},
) => {
try {
diff --git a/packages/cli/src/commands/template/list.ts b/packages/cli/src/commands/template/list.ts
index 5d30d5275..98c15dafc 100644
--- a/packages/cli/src/commands/template/list.ts
+++ b/packages/cli/src/commands/template/list.ts
@@ -2,7 +2,7 @@ import * as commander from 'commander'
import * as e2b from '@e2b/sdk'
import { ensureAccessToken } from 'src/api'
-import { asHeadline, asPrimary } from '../../utils/format'
+import { asDim } from 'src/utils/format'
const listTemplates = e2b.withAccessToken(
e2b.api.path('/envs').method('get').create(),
@@ -20,7 +20,6 @@ export const listCommand = new commander.Command('list')
console.log(asHeadline('Sandbox templates:'))
-
const templates = templatesResponse.data
if (!templates?.length) {
@@ -29,8 +28,12 @@ You can create a template by running ${asPrimary('e2b template build')} or visit
} else {
templates
.sort((a, b) => a.envID.localeCompare(b.envID))
- .forEach((template: { envID: string }) => {
- console.log(template.envID)
+ .forEach(template => {
+ if (template.aliases?.length) {
+ console.log(`${template.aliases?.join(', ')} (${asDim(template.envID)})`)
+ } else {
+ console.log(`${template.envID}`)
+ }
})
}
diff --git a/packages/cli/src/commands/template/shell.ts b/packages/cli/src/commands/template/shell.ts
index c94873f81..f29dfd178 100644
--- a/packages/cli/src/commands/template/shell.ts
+++ b/packages/cli/src/commands/template/shell.ts
@@ -14,9 +14,9 @@ export const shellCommand = new commander.Command('shell')
const apiKey = ensureAPIKey()
const template: Pick<e2b.components['schemas']['Environment'], 'envID'> =
- {
- envID: id,
- }
+ {
+ envID: id,
+ }
await connectSandbox({ apiKey, template: template })
// We explicitly call exit because the sandbox is keeping the program alive.
@@ -29,15 +29,16 @@ export const shellCommand = new commander.Command('shell')
})
async function connectSandbox({
- apiKey,
- template,
- }: {
+ apiKey,
+ template,
+}: {
apiKey: string;
template: Pick<e2b.components['schemas']['Environment'], 'envID'>;
}) {
const sandbox = await e2b.Sandbox.create({
apiKey,
id: template.envID,
+ logger: console,
})
if (sandbox.terminal) {
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index fd1e4d60c..2bd2f93b9 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -14,6 +14,7 @@ const configCommentHeader = `# This is a config for E2B sandbox template
`
export const configSchema = yup.object({
+ name: yup.string(),
id: yup.string().required(),
dockerfile: yup.string().required(),
})