When no artifacts are found during scanning, `menu_options` remains an
empty array. With `set -euo pipefail` active, expanding `${menu_options[@]}`
on an empty array causes a fatal "unbound variable" error (line 1325).
Add an early-return guard after the spinner stops: if no items were found,
print a friendly "No artifacts found to purge" message and exit cleanly.
Fixes#546
- Add global caching for `detect_architecture`, `get_darwin_major`, `get_optimal_parallel_jobs`, and `is_ansi_supported` to reduce subshell overhead.
- Improve robustness of `get_lsregister_path` by returning 1 on failure.
- Enhance security of `get_user_home` by replacing `eval echo` with `id -P`.
When Mole is called from GUI applications (e.g., SwiftUI apps), the
request_sudo_access() function would fail with '/dev/tty: Device not
configured' error because /dev/tty is not available in non-TTY contexts.
This commit adds automatic detection of the runtime environment and uses
macOS native password dialog (via osascript) when running in GUI mode,
while preserving all existing TTY behavior including Touch ID support.
Changes:
- Detect TTY availability before attempting terminal-based authentication
- Use osascript to display native password dialog in GUI mode
- Maintain backward compatibility with all terminal-based workflows
- Ensure secure password handling (unset after use)
Fixes commands like 'mole clean', 'mole optimize', 'mole purge' when
invoked from GUI applications.
* feat: add --json flag to analyze command
* feat: implement JSON output mode for analyze
* refactor: rename jsonOutput flag to jsonMode to avoid conflict
Network rate calculation requires two samples to compute the delta.
In JSON mode, the collector was only called once, causing the network
field to always return nil.
This change adds a second collection call with a 1-second interval,
allowing the network rates to be calculated properly.
- Replace inline dynamic formatting with shared bytes_to_human_kb()
- Apply to both clean and purge commands
- Simplify movie comparison with integer arithmetic
- Use array slicing instead of manual loop for splitting dirs
- Remove redundant early returns with duplicated safe_clean calls
- Consolidate cache/logs cleanup to single location at function end
Add --json command-line flag to mo status that outputs system metrics
in JSON format without requiring a TTY environment.
This enables:
- Integration with GUI applications (e.g., native macOS apps)
- Use in automation scripts and monitoring systems
- Piping output to tools like jq for data extraction
- Recording metrics for analysis
Implementation:
- Add JSON struct tags to all metric types
- Add --json flag using Go's flag package
- Implement runJSONMode() for one-time metric collection
- Refactor main() to support both TUI and JSON modes
- Maintain 100% backward compatibility (default TUI unchanged)
Testing:
- All 454 existing tests pass
- JSON output validated with jq and python json.tool
- Pipeline and redirection work correctly
- No breaking changes to existing functionality