Skip to content

Add --config-file command line parameter #917

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

Merged

Conversation

anakinj
Copy link
Contributor

@anakinj anakinj commented Oct 8, 2020

This addresses #756

It's still a little WIP but comments are appreciated at this point, probably going to do some refactorings.

Was thinking we could support YAML configuration files also, should be pretty straightforward to implement.

@anakinj anakinj force-pushed the config-file-cli-param branch 3 times, most recently from ff4e1b1 to 52b9294 Compare October 9, 2020 04:53
@anakinj
Copy link
Contributor Author

anakinj commented Oct 16, 2020

I think I'm done with this. Comments are appreciated.

Copy link
Collaborator

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anakinj Thanks for the thorough Pull Request!

I made inline comments, and you can process them as and when you wish to, let me know when you want me to look again, and I'll get back to you.

let(:argv) { [] }

before do
# Calling abort will abort the test run, allow calls to abort to not accidentaly get positive falses
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good context in this comment!

end
end

context "when --config-file is overriden to something that is not there" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context "when --config-file is overriden to something that is not there" do
context "when --config-file is overridden to something that is not there" do

end
end

context "when option with incorrect type is given" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context "when option with incorrect type is given" do
context "when an option with incorrect type is given" do

@@ -22,29 +44,22 @@ module GitHubChangelogGenerator
#
class ParserFile
# @param options [Hash] options to be configured from file contents
# @param file [nil,IO] configuration file handle, defaults to opening `.github_changelog_generator`
def initialize(options, file = open_settings_file)
# @param io [nil,IO] configuration file handle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @param io [nil,IO] configuration file handle
# @param io [nil, IO] configuration file handle

class FileParserChooser
def initialize(options, config_file)
@options = options
@config_file = config_file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Would anything become easier or cooler if Pathname(config_file) was used here? I'm a big fan of Pathname. https://rubyapi.org/3.0/o/pathname

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would. Great tip, will start using Pathname even more in the future !


argv_parser.parse!(argv) # parse first to get config_file
FileParserChooser.new(options, options[:config_file]).parse!
argv_parser.parse!(argv) # parse again to override whatever was read from the config file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: This all seems alright, and perhaps it doesn't need to be any more of a pipeline than now.

But I was thinking "what if we add more ways to input configuration? Would they have the style XyzParser.new(options, options[:xyz_special_option_setting]).parse! too?

This comment is prefixed is "Minor:" which means "you can read it, and you absolutely don't have to act or react to it".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to make the parameters even more generic to the parsers like: FileParserChooser.new(options).parse!

Then the parser can choose what/if it will do and the caller don't really need to care about special parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took some inspiration from this comments and changed the parsing totally from the first proposed version.

@@ -202,6 +189,9 @@ def self.setup_parser(options)
opts.on("--cache-file [CACHE-FILE]", "Filename to use for cache. Default is github-changelog-http-cache in a temporary directory.") do |cache_file|
options[:cache_file] = cache_file
end
opts.on("--config-file [CONFIG-FILE]", "Path to configuration file. Default is .github_changelog_generator.") do |config_file|
options[:config_file] = config_file
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

#945 now registered the issue (which you didn't introduce, mind you).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The surroundings impact how you do things :) Will adjust.

options = default_options

ParserFile.new(options).parse!
class ArgvParser
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to make the file layout more regular, could this class be in its own file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be yes. I'll adjust

@olleolleolle olleolleolle changed the title --config-file command line parameter Add --config-file command line parameter Mar 23, 2021
@anakinj
Copy link
Contributor Author

anakinj commented Mar 23, 2021

Thanks @olleolleolle for the super-positive-and-nice review. I will take a look at the suggestions/comments when time allows.

@anakinj anakinj force-pushed the config-file-cli-param branch 4 times, most recently from 4508d6d to a41a853 Compare April 10, 2021 20:48
@anakinj anakinj force-pushed the config-file-cli-param branch from a41a853 to ff552d5 Compare April 10, 2021 20:51
@anakinj
Copy link
Contributor Author

anakinj commented Apr 10, 2021

Great comments.

I did some adjustments and it turned out pretty nice I think.

puts opts
exit
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we have merged this, or earlier, we can figure out a way to not repeat (and need to maintain 2 copies of) these opts.on invocations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not totally sure I follow. But where is the copy?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it was only me being momentarily confused, we're already at that place. Perfect!

ArgvParser, # Parse arguments first to get initial options populated
FileParserChooser, # Then parse possible configuration files
ArgvParser # Lastly parse arguments again to keep the given arguments the strongest
].freeze
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely documented!

Copy link
Collaborator

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! We have gotten somewhere. Many small improvements.

Do you feel ready to merge?

@anakinj
Copy link
Contributor Author

anakinj commented Apr 11, 2021

Im done for now, so yeah.

@olleolleolle olleolleolle merged commit 90051d1 into github-changelog-generator:master Apr 11, 2021
@olleolleolle
Copy link
Collaborator

@anakinj Many thanks for taking the time to build & to revisit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants