Skip to content

armgit / E2B

Public Imported from GitHub
0

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

List sandbox templates with aliases

Jakub Novak1908ae2d3011
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 7a30bc3f2..e4dc3fe95 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -56,6 +56,7 @@
"chalk": "^5.3.0",
"commander": "^11.1.0",
"common-tags": "^1.8.2",
+ "console-table-printer": "^2.11.2",
"ignore": "^5.2.4",
"open": "^9.1.0",
"strip-ansi": "^7.1.0",
diff --git a/packages/cli/src/commands/template/list.ts b/packages/cli/src/commands/template/list.ts
index 98c15dafc..dd4dc022e 100644
--- a/packages/cli/src/commands/template/list.ts
+++ b/packages/cli/src/commands/template/list.ts
@@ -1,8 +1,9 @@
+import * as chalk from 'chalk'
+import * as tablePrinter from 'console-table-printer'
import * as commander from 'commander'
import * as e2b from '@e2b/sdk'
import { ensureAccessToken } from 'src/api'
-import { asDim } from 'src/utils/format'
const listTemplates = e2b.withAccessToken(
e2b.api.path('/envs').method('get').create(),
@@ -18,27 +19,29 @@ export const listCommand = new commander.Command('list')
const templatesResponse = await listTemplates(accessToken, {})
- console.log(asHeadline('Sandbox templates:'))
+ console.log(
+ chalk.default.underline(chalk.default.green('Sandbox templates')),
+ )
const templates = templatesResponse.data
if (!templates?.length) {
- console.log(`No templates found.\n
-You can create a template by running ${asPrimary('e2b template build')} or visit E2B docs ${asPrimary('(https://e2b.dev/docs/guide/custom-sandbox)')} to learn more.`)
+ console.log('No templates found.')
} else {
- templates
- .sort((a, b) => a.envID.localeCompare(b.envID))
- .forEach(template => {
- if (template.aliases?.length) {
- console.log(`${template.aliases?.join(', ')} (${asDim(template.envID)})`)
- } else {
- console.log(`${template.envID}`)
- }
- })
- }
+ const table = new tablePrinter.Table({
+ title: 'Sandbox templates',
+ columns: [
+ { name: 'envID', alignment: 'left' , title: "EnvID"},
+ { name: 'aliases', alignment: 'left', title: 'Name', color: 'blue' },
+ ],
+ disabledColumns: ['public', 'buildID'],
+ rows: templates.map((template) => ({...template, aliases: template.aliases ? template.aliases.join(" | ") : undefined})),
+ sort: (row1, row2) => row1.envID.localeCompare(row2.envID)
+ })
+ table.printTable()
process.stdout.write('\n')
- } catch (err: any) {
+ }} catch (err: any) {
console.error(err)
process.exit(1)
}