Skip to content

feat: add --sd-storage command to query SD card space - #31

Merged
tylerkron merged 2 commits into
mainfrom
feature/sd-storage-command
Jun 19, 2026
Merged

tylerkron merged 2 commits into
mainfrom
feature/sd-storage-command

Conversation

@tylerkron

@tylerkron tylerkron commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a --sd-storage command that queries the SD card's free/used/total space via GetSdCardStorageAsync() and prints a formatted summary:

Querying SD card storage...
  Free:    7,810,023,424 bytes (7448.22 MiB)
  Used:        5,111,808 bytes (4.88 MiB)
  Total:   7,815,135,232 bytes (7453.09 MiB)
  Used%: 0.1%

Includes the help-text entry and a README line.

Daqifi.Core dependency

GetSdCardStorageAsync was added in daqifi-core#214 and shipped in Daqifi.Core 0.24.0 (now published on NuGet). This PR bumps the package reference 0.20.0 → 0.24.0. The default dotnet build restores cleanly against the published package (0 warnings / 0 errors).

🤖 Generated with Claude Code

Adds a --sd-storage flag that calls GetSdCardStorageAsync() and prints
the SD card free/used/total bytes and used percentage. Includes the
help-text entry and a README line.

Requires the SD-storage API (GetSdCardStorageAsync) added in daqifi-core
#214, first shipping in Daqifi.Core 0.24.0; bumps the package reference
from 0.20.0 to 0.24.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tylerkron
tylerkron marked this pull request as ready for review June 19, 2026 20:59
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add --sd-storage CLI command to report SD card capacity usage
✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

Description

• Add --sd-storage flag to query SD card free/used/total bytes.
• Print a formatted storage summary including used percentage.
• Bump Daqifi.Core to 0.24.0 and document the new flag in README/help.
Diagram

graph TD
  A["Program.Main"] --> B["CliOptions.Parse\n(--sd-storage)"] --> C{"Any SD flag?"}
  C -->|"--sd-storage"| D["RunSdCardOperationAsync"] --> E["GetSdCardStorageAsync"] --> F[("SD card")]
  D --> G["Format + print summary"]
Loading
High-Level Assessment

The PR’s approach is the most direct and consistent with the existing flag-based CLI: add a boolean option, route through the existing SD-card operation handler, call the new Daqifi.Core API, and print results. Alternative larger refactors (e.g., adopting a command framework like System.CommandLine or restructuring SD operations into subcommands) would be disproportionate to the scope of adding a single flag.

Files changed (3) +22 / -3

Enhancement (1) +20 / -2
Program.csAdd --sd-storage option and SD storage reporting output +20/-2

Add --sd-storage option and SD storage reporting output

• Adds a new 'SdStorage' CLI option, includes it in SD-card routing, and implements a new SD-card operation that calls 'GetSdCardStorageAsync()' and prints free/used/total bytes plus used percentage. Also extends help text to advertise the new flag.

Program.cs

Documentation (1) +1 / -0
README.mdDocument --sd-storage in CLI usage list +1/-0

Document --sd-storage in CLI usage list

• Adds a README entry describing the new '--sd-storage' flag and what it prints.

README.md

Other (1) +1 / -1
Daqifi.Core.Cli.csprojBump Daqifi.Core dependency to 0.24.0 +1/-1

Bump Daqifi.Core dependency to 0.24.0

• Updates the Daqifi.Core package reference from 0.20.0 to 0.24.0 to pull in the new SD card storage API required by the CLI flag.

Daqifi.Core.Cli.csproj

@qodo-code-review

qodo-code-review Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. SD flags not exclusive ✓ Resolved 🐞 Bug ≡ Correctness
Description
CliOptions allows multiple SD operation flags simultaneously, but RunSdCardOperationAsync executes
only the first matching branch (now starting with SdStorage), silently skipping other requested SD
actions. This can cause intended commands like --sd-log-stop/--sd-format to not run when combined
with another SD flag.
Code

Program.cs[R687-700]

+            if (options.SdStorage)
+            {
+                Console.WriteLine("Querying SD card storage...");
+                var storage = await streamingDevice.GetSdCardStorageAsync();
+                Console.WriteLine($"  Free:  {storage.FreeBytes,15:N0} bytes ({storage.FreeBytes / 1024.0 / 1024.0:F2} MiB)");
+                Console.WriteLine($"  Used:  {storage.UsedBytes,15:N0} bytes ({storage.UsedBytes / 1024.0 / 1024.0:F2} MiB)");
+                Console.WriteLine($"  Total: {storage.TotalBytes,15:N0} bytes ({storage.TotalBytes / 1024.0 / 1024.0:F2} MiB)");
+                if (storage.TotalBytes > 0)
+                {
+                    Console.WriteLine($"  Used%: {storage.UsedBytes * 100.0 / storage.TotalBytes:F1}%");
+                }
+            }
+            else if (options.SdList)
            {
Evidence
RunSdCardOperationAsync() dispatches SD operations via an if/else-if chain starting with the newly
added SdStorage branch, so only one SD action can run. --sd-storage is parsed as a flag, but no
mutual-exclusion validation exists (unlike firmware commands), so conflicting SD flags can be
provided and will be silently ignored at runtime.

Program.cs[687-715]
Program.cs[1522-1609]
Program.cs[1651-1675]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The CLI accepts multiple SD-operation flags at the same time (e.g. `--sd-storage --sd-log-stop`), but `RunSdCardOperationAsync()` uses an `if/else-if` chain and will only execute the first matching operation. This silently ignores the other SD flags and can lead to the user thinking an action executed when it did not.

## Issue Context
- `--sd-storage` is newly added and placed at the top of the SD operation dispatch chain, increasing the chance of accidental conflicts.
- The CLI already validates mutual exclusivity for firmware commands, but there is no equivalent validation for SD commands.

## Fix Focus Areas
- Program.cs[1522-1690]
- Program.cs[687-759]

### Suggested fix approach
- In `CliOptions.Parse`, compute an `sdCommandCount` that includes:
 - `SdStorage`, `SdList`, `SdLogStart`, `SdLogStop`, `SdFormat`
 - `SdDeleteFileName != null`, `SdDownloadFileName != null`
- If `sdCommandCount > 1`, add an error like: `"Specify only one SD card command at a time."`
- (Optional but consistent) If `--sd-log-format` is supplied without `--sd-log-start`, add a parse error (since it otherwise silently has no effect).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

2. SD storage docs mismatch ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
README.md documents --sd-storage as “USB/Serial only” while PrintHelp() lists --sd-storage
without that note, creating conflicting usage guidance. This can lead users to attempt the command
over an unsupported transport based on whichever doc they read.
Code

Program.cs[1432]

+        Console.WriteLine("  --sd-storage             Show SD card free/used/total space.");
Evidence
The help text added for --sd-storage does not mention “USB/Serial only,” while the README
explicitly does, so users get different guidance depending on where they look.

Program.cs[1430-1438]
README.md[47-49]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`--sd-storage` is documented as “USB/Serial only” in the README, but the CLI `--help` output does not include that limitation for `--sd-storage` (or `--sd-list`). This creates inconsistent user guidance.

## Issue Context
Both README and `PrintHelp()` are user-facing docs; they should agree on any transport limitation.

## Fix Focus Areas
- Program.cs[1430-1439]
- README.md[45-53]

### Suggested fix approach
- Either:
 - Update `PrintHelp()` lines for `--sd-list` and `--sd-storage` to include “(USB/Serial only)” (matching README), **or**
 - Remove/adjust the “USB/Serial only” wording in README if the operations are actually supported over TCP.
- Keep wording/casing consistent across both places.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Qodo review of #31:
- RunSdCardOperationAsync dispatches SD operations via a single if/else-if
  chain, so combining flags (e.g. --sd-storage --sd-log-stop) silently ran
  only the first. Add an sdCommandCount check mirroring the firmware-command
  validation: "Specify only one SD card command at a time."
- --help now marks --sd-list and --sd-storage as "(USB/serial only)" to match
  the README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tylerkron

Copy link
Copy Markdown
Contributor Author

Qodo feedback addressed (commit 00ff498)

1. SD flags not exclusive (🐞 Correctness) — fixed. Agreed: RunSdCardOperationAsync dispatches via a single if/else-if chain, so combining SD flags silently ran only the first (now --sd-storage, at the top). Added an sdCommandCount check in CliOptions.Parse mirroring the existing firmware-command validation — conflicting flags now error up front:

$ Daqifi.Core.Cli --sd-storage --sd-list --serial /dev/cu.usbmodem2101
Specify only one SD card command at a time.
Use --help to see available options.

2. SD storage docs mismatch (🐞 Maintainability) — fixed. Agreed: README marked --sd-storage as "USB/Serial only" but --help didn't. --help now annotates both --sd-list and --sd-storage with "(USB/serial only)", matching the README and the existing --sd-download line.

Bench test (real hardware)

Built against the published Daqifi.Core 0.24.0 NuGet package (default dotnet build, 0 warnings / 0 errors — no local-core override) and run against a connected DAQiFi Nq1 over USB/serial:

$ Daqifi.Core.Cli --sd-storage --serial /dev/cu.usbmodem2101
Connected to /dev/cu.usbmodem2101 @ 9600 baud
Querying SD card storage...
  Free:    7,810,023,424 bytes (7448.22 MiB)
  Used:        5,111,808 bytes (4.88 MiB)
  Total:   7,815,135,232 bytes (7453.09 MiB)
  Used%: 0.1%
exit code: 0

✅ Daqifi.Core 0.24.0 is live on NuGet, the default build is clean, and --sd-storage works end-to-end against real hardware.

🤖 Generated with Claude Code

@tylerkron
tylerkron merged commit 4925967 into main Jun 19, 2026
@tylerkron
tylerkron deleted the feature/sd-storage-command branch June 19, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant