Refactor ls command, enhance argument handling, and add unit tests#198
Open
asideofcode-dev wants to merge 3 commits intobrevdev:mainfrom
Open
Refactor ls command, enhance argument handling, and add unit tests#198asideofcode-dev wants to merge 3 commits intobrevdev:mainfrom
ls command, enhance argument handling, and add unit tests#198asideofcode-dev wants to merge 3 commits intobrevdev:mainfrom
Conversation
- Refactored the `ls` command to include argument routing directly within the `RunE` function for improved clarity and maintainability. - Replaced `if-else` statements in `handleLsArg` with a cleaner `switch` statement. - Updated the help output to properly display valid arguments for the `ls` command, enhancing user guidance. - Improved error handling, particularly for invalid arguments and admin-only operations. - Refactored `NewCmdLs` to include dynamic routing and improved user experience. - Introduced new unit tests for various `ls` command scenarios, ensuring coverage for no args, valid args, invalid args, and specific flag handling. - Added a `NewTestTerminal` function to facilitate testing by providing an easily configurable terminal instance with buffers for `stdout`, `stderr`, and verbose output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Full disclosure, this is an attempt to get hired 😄 )
Summary
This PR introduces a comprehensive refactor of the
brev lscommand within our CLI, focusing on improving argument handling, user guidance, and overall maintainability. Additionally, the PR adds robust unit tests to ensure the reliability of these changes and provides better tools for testing the terminal output.Key Changes
Refactored Argument Handling:
RunEfunction of thecobra.Commandto simplify the command's logic.if-elsestructure inhandleLsArgwith a more concise and readableswitchstatement.ValidArgsto include all possible singular and plural forms of valid arguments ("orgs", "workspaces", "users", "hosts").Enhanced Help Output:
lscommand now properly lists all valid arguments in the help message, providing users with clear guidance on the available options.Improved Error Handling:
Unit Testing:
lscommand to cover a variety of scenarios, including:--all,--org).NewTestTerminalfunction to support testing, allowing the capture and inspection of terminal output (stdout,stderr, and verbose output).Terminal Utility Enhancements:
Terminalstruct to include anOut()method to access the output writer.Impact
lscommand is now more intuitive and user-friendly, with clearer guidance and improved error messaging.lscommand behaves as expected across a variety of use cases.