-
Notifications
You must be signed in to change notification settings - Fork 22
Refactor CLI into a modular src layout with a single entrypoint (main.rs), src/commands, and shared src/utils (with focused unit tests)
#358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
making code more modular and rust idomatic code by distributing in subpackages Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
it has its own test cases to verify behaviour and a rust header doc Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…nd directory utils it has its own test cases to verify behaviour and a rust header doc Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…r to existing commands Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…and more modular Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…bpackage which cleanly implements each command yet to add tests but added snapshot files to test it effectively Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…issues SDKMAN_DIR_ENV_VAR renamed to SDKMAN_DIR and linking can be changed Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…all back to the cli need to add test cases later and made code more efficient Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
… fall back to the cli need to add test cases later and made code more efficient Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
… fall back to the cli need to add test cases later and made code more efficient Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…I endpoints - updated snapshots and fixed default behaviour for clap command which disrupts tests Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
… format and other checks to ensure best practices Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
… well as fixing help tests to work for github actions Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
…windows machines as well Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com>
|
I also wanted to float one bigger-picture thought after working through this refactor. Would it be worth considering a longer-term direction where SDKMAN leans toward a single, first-class native binary as the main interface, rather than relying on multiple shell wrappers for different behaviours?
I understand the wrappers have real value today (compatibility, bootstrapping, user expectations), so I am not suggesting removing them abruptly. More that this PR nudged the codebase toward a structure that would support that direction cleanly if the project ever wanted it. |
|
Hi @keys-i, thanks for putting all that effort into this refactor. I can see the quality and it's appreciated. That said, I can't merge this. Before starting work like this, please jump on our Discord and chat with us first, as our contributing guidelines clearly state. This is a massive architectural change, and a quick conversation would have shown that it's not aligned with where we're heading. The reason is simple: we're doing a gradual, command-by-command rollout (check Discussion #18 if you want the details). We're in the process of strangling the old bash commands, where each new command supersedes the old. At the same time, our users are blissfully unaware that they are being migrated to Rust 🎉 Your structure assumes a different approach and architecture than what we're building toward. If you see specific pain points in the current approach, let's talk about those in Discord and figure out how to fix them incrementally. We'd love your help with that. Cheers! |
Totally fair, and thanks for the thoughtful feedback. Sorry I didn’t sync on Discord first. I missed the expectation in the contributing guidelines and I get why that matters, especially for architecture changes. I also just read through Discussion #18 and I understand the command by command strangler rollout you’re doing, with users staying unaware of the migration. I’ll stop pushing this refactor direction and I’m happy to close the PR (or leave it open as a reference if you prefer). If you can point me to the right Discord channel (or an invite link), I’ll jump in and align before doing any more work. If you’d like, I can help in a way that fits the rollout approach, for example:
If there are a couple of high priority commands or issues that would be most useful next, tell me what to grab and I’ll work incrementally from there. Cheers, |
|
Hey @keys-i, thanks so much for understanding. Let's close this PR for now and continue the discussion on Discord: We could open a new discussion item in the Discussions channel to identify where we can improve what we currently have. My first thoughts go to improving the integration test harness (and associated helpers). Also, we currently don't support CYGWIN on Windows, which would be a nice addition. I'd say these as the best places to begin. |
|
I'm closing this PR for now, but we still have it here on GH for reference. |
This PR refactors
sdkman_cli_nativeinto a more modular, Rust-idiomatic layout while keeping CLI behaviour stable. The main change is structural:src/main.rsbecomes the single entrypoint for parsing and dispatch, each subcommand lives insrc/commands/, and shared helpers move intosrc/utils/with small unit tests next to the utilities they validate. This reduces coupling, improves maintainability, and makes it easier to add new commands without touching unrelated areas.src/main.rsfor CLI parsing and dispatch onlysrc/commands/as focused modulessrc/utils/with small unit testsPath/PathBufand consistent error propagationMotivation
As the CLI grows and more edge cases are covered, the current structure makes it easy for command logic, parsing, and filesystem handling to become intertwined. That increases duplication, makes platform-specific issues harder to fix once, and pushes tests toward end-to-end execution even when validating a small parsing rule. This refactor tightens module boundaries so each layer has a clear job and can be tested in isolation, especially around file and path behaviour on different platforms.
New project structure
src/main.rssrc/commands/src/utils/Design overview
src/main.rsbecomes the only place where the application starts and the only place where CLI arguments are interpreted at a high level. It builds any minimal runtime context required and then hands off to a dispatcher insrc/commands. The dispatcher selects the appropriate command module and runs it. Commands contain subcommand behaviour but do not own low-level file reading, parsing, or path normalization; those details live insrc/utils.main.rscommands/utils/Commands module
Commands are organized as small modules under
src/commands/, typically one file per subcommand. This improves discoverability and keeps each command’s logic focused. Shared behaviour is pulled intosrc/utils/so commands remain thin and consistent.src/commands/mod.rsdefines dispatch and wiringsrc/commands/<command>.rsimplements the command logicutilsfor shared filesystem/parsing/path behaviourutilsUtils module and tests
src/utils/becomes the home for shared helpers used across commands, such as reading version/config files, parsing their contents, and handling paths consistently. Unit tests live alongside these utilities to validate tricky behaviour close to the implementation.src/utilsunit testssrc/utilsunit testssrc/utilsunit testsRust-idiomatic improvements
This refactor nudges the codebase toward idiomatic Rust by making paths first-class and keeping error handling consistent. Utilities accept
&Pathand return structured results with contextual errors, and commands orchestrate intent rather than re-implementing mechanics.Path/PathBufover string pathsBehaviour and compatibility
This PR is intended as a structural refactor rather than a feature change. The command set, flags, output shape, and exit codes should remain the same. Any differences should be limited to clearer, more consistent error context for file and path failures, without changing the meaning of failures.
utilsReviewer notes
This change is easiest to review in chunks: directory restructure and dispatch wiring, command migrations, utils consolidation, then the new unit tests. The key thing to verify is that
main.rsis only wiring, commands live insrc/commands, and shared logic lives insrc/utilswith tests close to the helpers.main.rsdoes parsing and dispatch onlysrc/commandssrc/utils