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

Up and attach #27

Merged
merged 9 commits into from
Oct 11, 2019
Merged

Up and attach #27

merged 9 commits into from
Oct 11, 2019

Conversation

Metallion
Copy link
Member

When running kaiser up followed by kaiser attach, it starts a docker container with the app in it, only to shut it down immediately and start up another one with an "attached" app in it.

This process has been bothering me a little for a while already so I quickly added a -a or --attach option to the kaiser up command.

Now the following command sets up the database and immediately attaches the source code in the current directory.

kaiser up -a

@degicat degicat requested a review from davidsiaw October 9, 2019 07:26
@degicat
Copy link

degicat commented Oct 9, 2019

@davidsiaw please review this

@davidsiaw
Copy link
Collaborator

This actually fixes #16

Copy link
Collaborator

@davidsiaw davidsiaw left a comment

Choose a reason for hiding this comment

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

Thanks! I did not know how to do this properly but you came up with a good solution.

Just some comments that could potentially improve the clarity of the new functionality.

end
end

attr_reader :opts
Copy link
Collaborator

Choose a reason for hiding this comment

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

This bunch of things is a great thing to abstract into a module. If you define this in a module, say a CliOptions module, you can extend CliOptions in the class Cli and it will be easier to see whats going on.

At the moment its really easy to confuse :opts and options.

Also with a CliOptions module renaming @options to @cli_options would make making the link easier.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Potentially you can also add it to only commands that require options if you do it this way. So it looks a lot less like magic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was also worried about opts and options being confusing. Especially since one is a class instance variable and the other is an instance variable. I'll put them in the module. I also like the idea of less magic. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I do think it's better to keep it in the superclass because this line over here relies on the cmd.class.options method existing and returning an array.

opts = cmd.define_options(global_opts + cmd.class.options)

I feel like this is more elegant than writing a check to see if the module was extended or not.

@@ -29,7 +44,7 @@ def define_options(global_opts = [])
# the scope to Optimist::Parser. We can still reference variables but we can't
# call instance methods of a Kaiser::Cli class.
u = usage
Optimist.options do
@opts = Optimist.options do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of making this global, can we just pass it in as a parameter to execute?

Copy link
Member Author

@Metallion Metallion Oct 10, 2019

Choose a reason for hiding this comment

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

I thought about too at first but the thing is execute calls a lot of private methods that are often shared between commands. We would have to pass the options to every single one.

Or I guess you could only pass them to the ones that actually make use of them which could make it more transparent. You could see at a glance which method uses options and which one does not.

I started writing this comment as a counter-argument but finished it thinking maybe you're right. lol

It would be less magic that way too.

Copy link
Collaborator

@davidsiaw davidsiaw left a comment

Choose a reason for hiding this comment

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

LGTM

@davidsiaw davidsiaw merged commit a09bbdc into master Oct 11, 2019
@davidsiaw davidsiaw deleted the up-and-attach branch October 11, 2019 08:02
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