Refactor ls command, enhance argument handling, and add unit tests
#198
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.