Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Make CLI SDK examples copyable

Tomas Valentafd4003ce4026
diff --git a/.changeset/strong-ladybugs-shop.md b/.changeset/strong-ladybugs-shop.md
new file mode 100644
index 000000000..974c57a6f
--- /dev/null
+++ b/.changeset/strong-ladybugs-shop.md
@@ -0,0 +1,5 @@
+---
+"@e2b/cli": patch
+---
+
+Fix CLI SDK examples format
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts
index 63c036000..0504c7ae6 100644
--- a/packages/cli/src/commands/build.ts
+++ b/packages/cli/src/commands/build.ts
@@ -17,8 +17,8 @@ import {
asPrimary,
asPython,
asTypescript,
+ borderStyle,
withDelimiter,
- withMargin,
} from 'src/utils/format'
import { pathOption } from 'src/options'
import { createBlobFromFiles } from 'src/docker/archive'
@@ -278,18 +278,37 @@ await sandbox.close()`)
const examplesMessage = `You can use E2B Python or JS SDK to spawn sandboxes now.
Find more here - ${asPrimary('https://e2b.dev/docs/guide/custom-sandbox')} in ${asBold('Spawn and control your sandbox')} section.`
- const exampleUsage = `${withMargin(examplesMessage)}\n${withDelimiter(pythonExample, 'Python SDK')}${withDelimiter(typescriptExample, 'JS SDK', true)}`
+ const exampleHeader = boxen.default(examplesMessage, {
+ padding: {
+ bottom: 1,
+ top: 1,
+ left: 2,
+ right: 2,
+ },
+ margin: {
+ top: 1,
+ bottom: 1,
+ left: 0,
+ right: 0,
+ },
+ fullscreen(width) {
+ return [width, 0]
+ },
+ float: 'left',
+ })
+
+ const exampleUsage = `${withDelimiter(pythonExample, 'Python SDK')}${withDelimiter(typescriptExample, 'JS SDK', true)}`
console.log(
`\n✅ Building sandbox template ${asFormattedSandboxTemplate(
{
- aliases, ...template.data
+ aliases, ...template.data,
},
- )} finished.\n${boxen.default(exampleUsage, {
+ )} finished.\n${exampleHeader}${boxen.default(exampleUsage, {
float: 'left',
+ borderStyle,
padding: 0,
margin: 1,
- title: 'Usage examples',
})}`,
)
break
diff --git a/packages/cli/src/utils/format.ts b/packages/cli/src/utils/format.ts
index c02a8c027..de5f9f5e9 100644
--- a/packages/cli/src/utils/format.ts
+++ b/packages/cli/src/utils/format.ts
@@ -75,7 +75,7 @@ export function asPython(code: string) {
return highlight.default(code, { language: 'python', ignoreIllegals: true })
}
-const borderStyle = {
+export const borderStyle = {
topLeft: '',
topRight: '',
bottomLeft: '',
@@ -94,6 +94,7 @@ export function withDelimiter(content: string, title: string, isLast?: boolean)
borderStyle: {
...borderStyle,
top: '─',
+ bottom: isLast ? '─' : '',
},
titleAlignment: 'center',
float: 'left',
@@ -102,7 +103,7 @@ export function withDelimiter(content: string, title: string, isLast?: boolean)
height: 0,
fullscreen: w => [w, 0],
padding: {
- bottom: isLast ? 0 : verticalPadding,
+ bottom: isLast ? verticalPadding : verticalPadding,
left: horizontalPadding,
right: horizontalPadding,
top: verticalPadding,