File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { join } from "@std/path";
77import { Spinner } from "@std/cli/unstable-spinner" ;
88
99import { getAppFromConfig , readConfig , writeConfig } from "../config.ts" ;
10- import { error , parseSize , renderTemporalTimestamp , withApp } from "../util.ts" ;
10+ import { error , parseSizeToMib , renderTemporalTimestamp , withApp } from "../util.ts" ;
1111import { createTrpcClient , getAuth } from "../auth.ts" ;
1212import type { GlobalOptions } from "../main.ts" ;
1313import token_storage from "../token_storage.ts" ;
@@ -54,7 +54,7 @@ export const sandboxCreateCommand = new Command<SandboxContext>()
5454 token,
5555 org,
5656 lifetime : options . lifetime as `${number } s` | `${number } m` | "session" ,
57- memoryMb : parseSize ( options . memory ) ,
57+ memoryMb : parseSizeToMib ( options . memory ) ,
5858 } ) ;
5959 if ( options . lifetime === "session" || options . ssh ) {
6060 console . log ( `Created sandbox with id '${ sandbox . id } '` ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { Command } from "@cliffy/command";
22import { ensureOrg , type SandboxContext } from "./mod.ts" ;
33import { getAuth } from "../auth.ts" ;
44import { Client } from "@deno/sandbox" ;
5- import { formatSize , parseSize , tablePrinter } from "../util.ts" ;
5+ import { formatSize , parseSizeToMib , tablePrinter } from "../util.ts" ;
66
77export const volumesCreateCommand = new Command < SandboxContext > ( )
88 . description ( "Create a volume" )
@@ -23,7 +23,7 @@ export const volumesCreateCommand = new Command<SandboxContext>()
2323
2424 const volume = await client . volumes . create ( {
2525 slug : name ,
26- capacity : parseSize ( options . capacity ) ! ,
26+ capacity : parseSizeToMib ( options . capacity ) ! ,
2727 region : options . region ,
2828 } ) ;
2929
Original file line number Diff line number Diff line change @@ -194,7 +194,7 @@ export function formatSize(bytes: number): string {
194194 return `${ bytes } Bytes` ;
195195}
196196
197- export function parseSize ( size : string | undefined ) : number | undefined {
197+ export function parseSizeToMib ( size : string | undefined ) : number | undefined {
198198 if ( size === undefined ) return undefined ;
199199
200200 const match = size . match ( / ^ ( \d + ) ( G B | M B | K B | G i B | M i B | K i B ) $ / i) ;
@@ -205,21 +205,32 @@ export function parseSize(size: string | undefined): number | undefined {
205205 ) ;
206206 }
207207 const [ , numStr , unit ] = match ;
208- const num = parseInt ( numStr , 10 ) ;
208+ const num = parseFloat ( numStr ) ;
209+
210+ let bytes = 0 ;
211+
209212 switch ( unit . toLowerCase ( ) ) {
210213 case "gb" :
211- return num * GIGABYTE ;
214+ bytes = num * GIGABYTE ;
215+ break ;
212216 case "mb" :
213- return num * MEGABYTE ;
217+ bytes = num * MEGABYTE ;
218+ break ;
214219 case "kb" :
215- return num * KILOBYTE ;
220+ bytes = num * KILOBYTE ;
221+ break ;
216222 case "gib" :
217- return num * GIBIBYTE ;
223+ bytes = num * GIBIBYTE ;
224+ break ;
218225 case "mib" :
219- return num * MEBIBYTE ;
226+ bytes = num * MEBIBYTE ;
227+ break ;
220228 case "kib" :
221- return num * KIBIBYTE ;
229+ bytes = num * KIBIBYTE ;
230+ break ;
222231 }
232+
233+ return Math . floor ( bytes / MEBIBYTE ) ;
223234}
224235
225236export function tablePrinter < T > (
You can’t perform that action at this time.
0 commit comments