Skip to content

Add -o flag support to flash command #4937

@rdon-key

Description

@rdon-key

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 and flash commands, inconsistent parameter handling

Approach 2: Refactor Build Function (Better Long-term Solution)

  • Modify Build function in main.go to use compileopts.Options instead of separate outpath parameter
  • This would unify the output handling logic between build and flash 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestnext-releaseWill be part of next release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions