Skip to content
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 option to config to parse or not command line parameters #483

Merged
merged 11 commits into from
Nov 30, 2018
Merged

Add option to config to parse or not command line parameters #483

merged 11 commits into from
Nov 30, 2018

Conversation

diegogub
Copy link
Contributor

Description of the Change

Added option into config to avoid parsing command line parameters, sometime users want to define their own parameters instead of using Kemal ones.

Benefits

Freedom for users to choose others libs or other command line parameters without running into Kemal InvalidOption exception. For example I'm using : http://docopt.org/

Possible Drawbacks

I don't see any positive on keeping this feature, I cannot find the utility of a web framework reading defined command line parameters. Also It's not well documented.

Thank you!

@straight-shoota
Copy link
Contributor

I think a better solution would be an optional parameter to Kemal.run which has ARGV as default value. If you don't want to parse cli options, just set it to nil.

@diegogub
Copy link
Contributor Author

@straight-shoota actually that was my first approach but I felt it was invasive over the main run procedure, but I guess it would be fine too

@diegogub
Copy link
Contributor Author

@straight-shoota would look like this: Kemal.run(args: nil)

@@ -17,16 +17,24 @@ module Kemal
self.run(nil)
end

def self.run(args = ARGV)
Copy link
Contributor

Choose a reason for hiding this comment

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

This overload should be merged with the previous one.

src/kemal.cr Outdated
# Overload of `self.run` to allow just a block.
def self.run(&block)
self.run nil, &block
end

def self.run(port : Int32?, args = ARGV )
Copy link
Contributor

Choose a reason for hiding this comment

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

This overload should be merged with the first one.

src/kemal/cli.cr Outdated
@ssl_enabled = false
@key_file = ""
@cert_file = ""
@config = Kemal.config
read_env
parse
if args != nil
Copy link
Contributor

Choose a reason for hiding this comment

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

just if args is enough.

src/kemal/cli.cr Outdated
@ssl_enabled = false
@key_file = ""
@cert_file = ""
@config = Kemal.config
read_env
parse
if args != nil
parse
Copy link
Contributor

Choose a reason for hiding this comment

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

parse should actually receive args as argument and forward it to OptionParser#parse. Otherwise this whole thing doesn't make any more sense than a simple flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for your feedback @straight-shoota !

@straight-shoota
Copy link
Contributor

Could you please apply the formatter (crystal tool format) to your patch?

@diegogub
Copy link
Contributor Author

sure, sorry. Not used to crystal tools. Thanks

Copy link
Contributor

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

Looks great. 👍
@sdogruyol Do you think we should have a spec for this?

Copy link
Contributor

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

Actually, additions to the API docs would be nice!

@sdogruyol
Copy link
Member

This is great 👍 @diegogub would you like to add some API docs for this?

@diegogub
Copy link
Contributor Author

diegogub commented Sep 16, 2018

@sdogruyol sure!

@diegogub
Copy link
Contributor Author

diegogub commented Nov 2, 2018

Hi @sdogruyol , I added one line explaining this configuration, thanks

Copy link
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

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

Thank you @diegogub 👍

@sdogruyol sdogruyol merged commit a5d8df7 into kemalcr:master Nov 30, 2018
@diegogub
Copy link
Contributor Author

thank you! @sdogruyol

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.

3 participants