Skip to content

Conversation

@skatkov
Copy link
Owner

@skatkov skatkov commented Nov 16, 2025

No description provided.

Stanislav (Stas) Katkov added 5 commits November 16, 2025 01:29
- Change all formatters to use cmd.InOrStdin() instead of os.Stdin
  * jsonfmt, tomlfmt, xmlfmt, cssfmt, cssmin
  * csv2md, tsv2md

- Simplify complex input detection in urls, base64, count
  * Remove file path auto-detection
  * Keep simple pattern: args[0] for string OR stdin for piped input
  * Aligns with Unix philosophy and improves testability

Benefits:
- All commands now testable with cmd.SetIn()
- Consistent API across all commands
- Simpler, more maintainable code
- Better follows Unix conventions

Note: base64_cli_test.go needs updates to use stdin instead of file args
- Rewrite all file path tests to use stdin instead
- Files are read and piped via stdin: cat file | devtui base64
- Maintains test coverage while aligning with new standardized pattern
- All tests pass successfully
Created internal/input package with 3 helper functions:
- ReadFromStdin: For formatters that only accept stdin
- ReadFromArgsOrStdin: For commands accepting args or stdin (returns string)
- ReadBytesFromArgsOrStdin: Same as above but returns bytes

Benefits:
- DRY principle: Eliminates duplicate input reading logic
- Testability: Helpers are fully tested (13 test cases)
- Consistency: All commands use same pattern
- Maintainability: Changes to input logic in one place
- Validation: Added Args: cobra.MaximumNArgs(1) to prevent multiple args

Refactored commands:
- json2toon, jsonfmt, tomlfmt, xmlfmt (stdin only)
- base64, urls, count (args or stdin)

All tests pass, zero linting issues.
@skatkov skatkov changed the title Standardize stdin reading Standardize stdin reading and args validation Nov 16, 2025
@skatkov skatkov merged commit b9f4062 into main Nov 16, 2025
8 checks passed
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.

2 participants