Open
Description
The tinygo flash
command currently doesn't support the -o
flag to save the built binary to a specified output file, while the tinygo build
command does. This inconsistency makes it inconvenient when users want to both flash a device and save the binary file for later use or distribution.
Current Behavior
tinygo build -o firmware.hex -target arduino main.go # Works - saves to firmware.hex
tinygo flash -o firmware.hex -target arduino main.go # Doesn't work - error message to stop.
Expected Behavior
tinygo flash -o firmware.hex -target arduino main.go # Should flash device AND save to firmware.hex
Proposed Implementation
I believe there are two possible approaches:
Approach 1: Minimal Change (Immediate Solution)
- Modify
Flash
function to copy the built binary to the specified output path after successful build - Pass
outpath
as an additional parameter to the Flash function - Pros: Minimal risk, easy to review, maintains backward compatibility
- Cons: Duplicates output logic between
build
andflash
commands, inconsistent parameter handling
Approach 2: Refactor Build Function (Better Long-term Solution)
- Modify
Build
function inmain.go
to usecompileopts.Options
instead of separateoutpath
parameter - This would unify the output handling logic between
build
andflash
commands - Pros: Cleaner architecture, consistent design, eliminates code duplication
- Cons: Larger change, requires more careful testing
Personal Preference: I lean toward Approach 2 (refactoring the Build function) as it creates a more consistent and maintainable codebase. However, I understand that Approach 1 might be preferred for minimizing change scope.
Would appreciate feedback on which approach the maintainers prefer before submitting a pull request.