-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add missing jo options #13
base: master
Are you sure you want to change the base?
Add missing jo options #13
Conversation
Don't risk committing the result of `go build`, ignore it via .gitignore.
Add support for several options that jo supports but gjo does not - -B -- disable treating true/false as bool - -e -- empty stdin is not an error - -n -- ignore keys with empty values - read from stdin if not args are supplied It adds code to handle the various features, modifies the run function to take an io.Reader as an argument for testability, and calls the run function with os.Stdin in main. It modifies the TestRun test: - The test cases have been updated: - renamed fields to be clear about meaning - only non-zero test values need to be supplied in the test case - provides stdin as a string.Reader - provides want_stdout to hold the expected output - Tests have been added for new features
main_test.go
Outdated
for test_flag, value := range _flags(test.flags) { | ||
flag.CommandLine.Set(test_flag, value) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for test_flag, value := range _flags(test.flags) { | |
flag.CommandLine.Set(test_flag, value) | |
} | |
for flag, value := range _flags(test.flags) { | |
flag.CommandLine.Set(flag, value) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't use flag, the LSP output sums it up nicely:
renaming this var "test_flag" to "flag" would shadow this reference to the imported package name declared here
@@ -133,7 +149,7 @@ func doVersion() error { | |||
}) | |||
} | |||
|
|||
func run() int { | |||
func run(stdin io.Reader) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testability, I think we should accept args
and return result
.
func run(args []string) string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to make changes here, but I don't quite understand what you want this to look like. Can you explain more fully?
- I think you're suggesting to pass in the
args
instead of referring to the globalflag.Args()
. Are you suggesting parsing the args and etc.. inmain
? - I find passing in an io.Reader instead of relying on os.Stdin or mocking it or using real files makes the table driven tests in main_test.go:TestRun cleaner (possible).
- What result do you want to return? It's currently returning success/failure, which is easily testable in
main_test.go:TestRun
, along with the output and stderr.
- use camelCase instead of snake_case for variable names (sorry, I've been dealing with a bunch of python...). - rename functiont that returns default flags to defaultFlags.
Add support for several options that jo supports but gjo does not
It adds code to handle the various features, modifies the run function
to take an io.Reader as an argument for testability, and calls the run
function with os.Stdin in main.
It modifies the TestRun test: