fix: allow config file to load showLineNumbers
Changes
- Added in a fix to allow the
showLineNumbersconfig option to be loaded from the config file - Previously it seems unclear on how to setup the
showLineNumberskey within the config, and while there was support added for configuring theshowLineNumbersflag, it couldn't be read from the config file, since thevalidateOptionsmethod would not retrieve the key from the config file - Hence changed it so that it does retrieve the
showLineNumberskey from the config file, and use it as needed - Updated the README.md to also provide an example on how to setup both the keys
Testing Notes
Ran
go build
./glow config
# added in `preserveNewLines: true` and `showLineNumbers: true` key
and for testing purposes to see if the config option was being read added in
func validateOptions(cmd *cobra.Command) error {
// grab config values from Viper
width = viper.GetUint("width")
mouse = viper.GetBool("mouse")
pager = viper.GetBool("pager")
showAllFiles = viper.GetBool("all")
preserveNewLines = viper.GetBool("preserveNewLines")
+ panic(fmt.Sprintf("preserveNewLines: %v, showLineNumbers: %v", preserveNewLines, showLineNumbers))
to showcase the configurations are being read
Previously:
When preserveNewLines: true and showLineNumbers: true within the config, the panic output shows that
preserveNewLines is being recognized, but showLineNumbers is not being recognized, which is unexpected
When ./glow -l is used, the panic output shows that the preserveNewLines is being recognized, and showLineNumbers is being recognized which is expected
After:
When preserveNewLines: true and showLineNumbers: true within the config, the panic output shows that
preserveNewLines is being recognized and showLineNumbers is being recognized, which is expected
When preserveNewLines: true and showLineNumbers: false within the config, the panic output shows that
preserveNewLines is being recognized and showLineNumbers is being recognized, which is expected
Removed the panic line used for testing purposes, ran go build; ./glow then navigated to the README.md to show that the line numbers are being shown, since the config has showLineNumbers: true
Other Notes
Related to https://github.com/charmbracelet/glow/issues/652
- [ ] Any tests that I can write?