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 ls
command 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:
RunE
function of thecobra.Command
to simplify the command's logic.if-else
structure inhandleLsArg
with a more concise and readableswitch
statement.ValidArgs
to include all possible singular and plural forms of valid arguments ("orgs", "workspaces", "users", "hosts").Enhanced Help Output:
ls
command now properly lists all valid arguments in the help message, providing users with clear guidance on the available options.Improved Error Handling:
Unit Testing:
ls
command to cover a variety of scenarios, including:--all
,--org
).NewTestTerminal
function to support testing, allowing the capture and inspection of terminal output (stdout
,stderr
, and verbose output).Terminal Utility Enhancements:
Terminal
struct to include anOut()
method to access the output writer.Impact
ls
command is now more intuitive and user-friendly, with clearer guidance and improved error messaging.ls
command behaves as expected across a variety of use cases.