Skip to content

Commit d2f2e84

Browse files
committed
feat(cli): change all toml keys to use snake_case
1 parent b56724a commit d2f2e84

6 files changed

Lines changed: 46 additions & 41 deletions

File tree

.changeset/petite-buckets-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cartesi/cli": patch
3+
---
4+
5+
change all toml keys to use snake_case

apps/cli/src/config.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import bytes from "bytes";
22
import { extname } from "node:path";
3-
import { type TomlPrimitive, parse as parseToml } from "smol-toml";
3+
import { parse as parseToml, type TomlPrimitive } from "smol-toml";
44

55
/**
66
* Typed Errors
@@ -367,16 +367,16 @@ const parseMachine = (value: TomlPrimitive): MachineConfig => {
367367

368368
return {
369369
assertRollingTemplate: parseOptionalBoolean(
370-
toml["assert-rolling-template"],
370+
toml.assert_rolling_template,
371371
),
372-
bootargs: parseStringArray(toml.bootargs),
372+
bootargs: parseStringArray(toml.boot_args),
373373
entrypoint: parseOptionalString(toml.entrypoint),
374-
finalHash: parseBoolean(toml["final-hash"], true),
374+
finalHash: parseBoolean(toml.final_hash, true),
375375
interactive: undefined,
376-
maxMCycle: parseOptionalNumber(toml["max-mcycle"]),
377-
noRollup: parseBoolean(toml["no-rollup"], false),
378-
ramLength: parseString(toml["ram-length"], DEFAULT_RAM),
379-
ramImage: parseString(toml["ram-image"], DEFAULT_RAM_IMAGE),
376+
maxMCycle: parseOptionalNumber(toml.max_mcycle),
377+
noRollup: parseBoolean(toml.no_rollup, false),
378+
ramLength: parseString(toml.ram_length, DEFAULT_RAM),
379+
ramImage: parseString(toml.ram_image, DEFAULT_RAM_IMAGE),
380380
store: "image",
381381
user: parseOptionalString(toml.user),
382382
};
@@ -398,11 +398,11 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
398398
const builder = parseBuilder((drive as TomlTable).builder);
399399
switch (builder) {
400400
case "directory": {
401-
const { extraSize, format, mount, directory, shared, user } =
401+
const { extra_size, format, mount, directory, shared, user } =
402402
drive as TomlTable;
403403
return {
404404
builder: "directory",
405-
extraSize: parseBytes(extraSize, 0),
405+
extraSize: parseBytes(extra_size, 0),
406406
format: parseFormat(format),
407407
mount: parseOptionalStringBoolean(mount),
408408
directory: parseRequiredString(directory, "directory"),
@@ -412,10 +412,10 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
412412
}
413413
case "docker": {
414414
const {
415-
buildArgs,
415+
build_args,
416416
context,
417417
dockerfile,
418-
extraSize,
418+
extra_size,
419419
format,
420420
image,
421421
mount,
@@ -426,11 +426,11 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
426426
} = drive as TomlTable;
427427
return {
428428
builder: "docker",
429-
buildArgs: parseStringArray(buildArgs),
429+
buildArgs: parseStringArray(build_args),
430430
image: parseOptionalString(image),
431431
context: parseString(context, "."),
432432
dockerfile: parseString(dockerfile, "Dockerfile"),
433-
extraSize: parseBytes(extraSize, 0),
433+
extraSize: parseBytes(extra_size, 0),
434434
format: parseFormat(format),
435435
mount: parseOptionalStringBoolean(mount),
436436
shared: parseOptionalBoolean(shared),
@@ -451,11 +451,11 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
451451
};
452452
}
453453
case "tar": {
454-
const { extraSize, filename, format, mount, shared, user } =
454+
const { extra_size, filename, format, mount, shared, user } =
455455
drive as TomlTable;
456456
return {
457457
builder: "tar",
458-
extraSize: parseBytes(extraSize, 0),
458+
extraSize: parseBytes(extra_size, 0),
459459
filename: parseRequiredString(filename, "filename"),
460460
format: parseFormat(format),
461461
mount: parseOptionalStringBoolean(mount),

apps/cli/tests/unit/config.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import * as fs from "node:fs";
22
import * as path from "node:path";
33
import { describe, expect, it } from "vitest";
44
import {
5+
defaultConfig,
6+
defaultMachineConfig,
57
InvalidBooleanValueError,
68
InvalidBuilderError,
79
InvalidBytesValueError,
810
InvalidDriveFormatError,
911
InvalidEmptyDriveFormatError,
1012
InvalidNumberValueError,
1113
InvalidStringValueError,
12-
RequiredFieldError,
13-
defaultConfig,
14-
defaultMachineConfig,
1514
parse,
15+
RequiredFieldError,
1616
} from "../../src/config.js";
1717

1818
const loadDriveConfig = (driveName: string) => {
@@ -97,7 +97,7 @@ shared = true`);
9797
describe("when parsing [machine]", () => {
9898
const config = `
9999
[machine]
100-
no-rollup = true
100+
no_rollup = true
101101
`;
102102
it("machine-config", () => {
103103
expect(parse(config)).toEqual({
@@ -111,7 +111,7 @@ shared = true`);
111111
it("should fail for invalid bootargs", () => {
112112
const invalidConfig = `
113113
${config}
114-
bootargs = ["no4lvl", "quiet", false]
114+
boot_args = ["no4lvl", "quiet", false]
115115
`;
116116
expect(() => parse(invalidConfig)).toThrowError(
117117
new InvalidStringValueError(false),
@@ -203,13 +203,13 @@ shared = true`);
203203
*/
204204
describe("when parsing fields types", () => {
205205
it("should fail for invalid boolean value", () => {
206-
expect(() => parse("[machine]\nno-rollup = 42")).toThrowError(
206+
expect(() => parse("[machine]\nno_rollup = 42")).toThrowError(
207207
new InvalidBooleanValueError(42),
208208
);
209209
});
210210

211211
it("should fail for invalid number value", () => {
212-
expect(() => parse("[machine]\nmax-mcycle = 'abc'")).toThrowError(
212+
expect(() => parse("[machine]\nmax_mcycle = 'abc'")).toThrowError(
213213
new InvalidNumberValueError("abc"),
214214
);
215215
});
@@ -230,7 +230,7 @@ shared = true`);
230230
const invalidTarDrive = `
231231
[drives.data]
232232
builder = "tar"
233-
extraSize = "abc"
233+
extra_size = "abc"
234234
filename = "data.tar"
235235
format = "ext2"
236236
`;
@@ -246,7 +246,7 @@ shared = true`);
246246
`[drives.data]
247247
builder = "directory"
248248
directory = "/data"
249-
extra-size = 128
249+
extra_size = 128
250250
`,
251251
),
252252
).not.toThrow();
@@ -256,7 +256,7 @@ shared = true`);
256256
`[drives.data]
257257
builder = "directory"
258258
directory = "/data"
259-
extra-size = "128MB"
259+
extra_size = "128MB"
260260
`,
261261
),
262262
).not.toThrow();
@@ -267,21 +267,21 @@ shared = true`);
267267
`[drives.data]
268268
builder = "directory"
269269
directory = "/data"
270-
extra-size = ${bigInt}
270+
extra_size = ${bigInt}
271271
`,
272272
),
273273
).not.toThrow();
274274
});
275275

276276
it("should fail for invalid boolean value", () => {
277-
expect(() => parse("[machine]\nfinal-hash = 42")).toThrowError(
277+
expect(() => parse("[machine]\nfinal_hash = 42")).toThrowError(
278278
new InvalidBooleanValueError(42),
279279
);
280280
});
281281

282282
it("should fail for invalid optional boolean value", () => {
283283
expect(() =>
284-
parse("[machine]\nassert-rolling-template = 42"),
284+
parse("[machine]\nassert_rolling_template = 42"),
285285
).toThrowError(new InvalidBooleanValueError(42));
286286
});
287287

apps/cli/tests/unit/config/fixtures/drives/data.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
[drives.data]
44
builder = "directory"
55
directory = "./data" # required
6-
extraSize = "100Mb" # optional. size is given by directory content size plus this amount
6+
extra_size = "100Mb" # optional. size is given by directory content size plus this amount
77
mount = "/var/lib/app" # optional, default is /mnt/{name}

apps/cli/tests/unit/config/fixtures/full.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# sdk = "cartesi/sdk:0.12.0"
22

33
# [machine]
4-
# assert-rolling-update = true
5-
# bootargs = ["no4lvl", "quiet", "earlycon=sbi", "console=hvc0", "rootfstype=ext2", "root=/dev/pmem0", "rw", "init=/usr/sbin/cartesi-init"]
4+
# assert_rolling_update = true
5+
# boot_args = ["no4lvl", "quiet", "earlycon=sbi", "console=hvc0", "rootfstype=ext2", "root=/dev/pmem0", "rw", "init=/usr/sbin/cartesi-init"]
66
# entrypoint = "/usr/local/bin/app"
7-
# final-hash = true
8-
# max-mcycle = 0
9-
# no-rollup = false
10-
# ram-image = "/usr/share/cartesi-machine/images/linux.bin" # directory inside SDK image
11-
# ram-length = "128Mi"
7+
# final_hash = true
8+
# max_mcycle = 0
9+
# no_rollup = false
10+
# ram_image = "/usr/share/cartesi-machine/images/linux.bin" # directory inside SDK image
11+
# ram_length = "128Mi"
1212

1313
# [drives.root]
1414
# builder = "docker"
1515
# dockerfile = "Dockerfile"
1616
# target = "docker-multi-stage-target"
1717
# format = "ext2"
1818
# format = "sqfs"
19-
# extraSize = "100Mb" # optional. size is given by directory content size plus this amount
19+
# extra_size = "100Mb" # optional. size is given by directory content size plus this amount
2020

2121
# [drives.data]
2222
# builder = "empty"
@@ -26,15 +26,15 @@
2626
# [drives.data]
2727
# builder = "directory"
2828
# directory = "./data" # required
29-
# extraSize = "100Mb" # optional. size is given by directory content size plus this amount
29+
# extra_size = "100Mb" # optional. size is given by directory content size plus this amount
3030
# format = "ext2"
3131
# format = "sqfs"
3232
# mount = "/var/lib/app" # optional, default is /mnt/{name}
3333

3434
# [drives.data]
3535
# builder = "tar"
3636
# filename = "build/files.tar"
37-
# extraSize = "100Mb" # optional. size is given by directory content size plus this amount
37+
# extra_size = "100Mb" # optional. size is given by directory content size plus this amount
3838
# mount = "/var/lib/app" # optional, default is /mnt/{name}
3939

4040
# [drives.doom]

apps/cli/tests/unit/config/fixtures/machine/no_boot.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[machine]
44
assert_rolling_update = false
5-
max-mcycle = 0
5+
max_mcycle = 0

0 commit comments

Comments
 (0)