Skip to content

Commit 73460a8

Browse files
committed
feat: specify ELF file on command line
close #9
1 parent 08324b0 commit 73460a8

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/help.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function cliHelp() {
1111
{green --quiet}, {green -q} Quiet: do not print version or status messages
1212
{green --expect-text} <string> Expect the given text in the output
1313
{green --fail-text} <string> Fail if the given text is found in the output
14+
{green --elf} <path> ELF file to simulate (default: read from wokwi.toml)
1415
{green --scenario} <path> Run the given scenario (yaml) file, path is relative to project root
1516
{green --serial-log-file} <path> Save the serial monitor output to the given file
1617
{green --screenshot-part} <string> Take a screenshot of the given part id (from diagram.json)

src/main.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import arg from 'arg';
22
import chalkTemplate from 'chalk-template';
3-
import { existsSync, readFileSync, writeFileSync, createWriteStream } from 'fs';
3+
import { createWriteStream, existsSync, readFileSync, writeFileSync } from 'fs';
44
import path, { join } from 'path';
55
import YAML from 'yaml';
66
import { APIClient } from './APIClient.js';
@@ -26,6 +26,7 @@ async function main() {
2626
'--help': Boolean,
2727
'--quiet': Boolean,
2828
'--version': Boolean,
29+
'--elf': String,
2930
'--expect-text': String,
3031
'--fail-text': String,
3132
'--serial-log-file': String,
@@ -42,6 +43,7 @@ async function main() {
4243
);
4344

4445
const quiet = args['--quiet'];
46+
const elf = args['--elf'];
4547
const expectText = args['--expect-text'];
4648
const failText = args['--fail-text'];
4749
const serialLogFile = args['--serial-log-file'];
@@ -74,8 +76,9 @@ async function main() {
7476
const rootDir = args._[0] || '.';
7577
const configPath = `${rootDir}/wokwi.toml`;
7678
const diagramFile = `${rootDir}/diagram.json`;
79+
const configExists = existsSync(configPath);
7780

78-
if (!existsSync(configPath)) {
81+
if (!elf && !configExists) {
7982
console.error(`Error: wokwi.toml not found in ${path.resolve(rootDir)}`);
8083
process.exit(1);
8184
}
@@ -85,12 +88,22 @@ async function main() {
8588
process.exit(1);
8689
}
8790

88-
const configData = readFileSync(configPath, 'utf8');
89-
const config = await parseConfig(configData, rootDir);
90-
const diagram = readFileSync(diagramFile, 'utf8');
91-
92-
const firmwarePath = join(rootDir, config.wokwi.firmware);
93-
const elfPath = join(rootDir, config.wokwi.elf);
91+
let firmwarePath;
92+
let elfPath;
93+
let config;
94+
95+
if (configExists) {
96+
const configData = readFileSync(configPath, 'utf8');
97+
config = await parseConfig(configData, rootDir);
98+
99+
firmwarePath = elf ?? join(rootDir, config.wokwi.firmware);
100+
elfPath = elf ?? join(rootDir, config.wokwi.elf);
101+
} else if (elf) {
102+
firmwarePath = elf;
103+
elfPath = elf;
104+
} else {
105+
throw new Error('Internal error: neither elf nor config exists');
106+
}
94107

95108
if (!existsSync(firmwarePath)) {
96109
console.error(`Error: firmware file not found: ${path.resolve(firmwarePath)}`);
@@ -102,7 +115,9 @@ async function main() {
102115
process.exit(1);
103116
}
104117

105-
const chips = loadChips(config.chip ?? [], rootDir);
118+
const diagram = readFileSync(diagramFile, 'utf8');
119+
120+
const chips = loadChips(config?.chip ?? [], rootDir);
106121

107122
const resolvedScenarioFile = scenarioFile ? path.resolve(rootDir, scenarioFile) : null;
108123
if (resolvedScenarioFile && !existsSync(resolvedScenarioFile)) {

0 commit comments

Comments
 (0)