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

split commands.go into multiple files #118

Merged
merged 1 commit into from Sep 30, 2021

Conversation

mihai-chiorean
Copy link
Contributor

commands.go was looking increasingly large. I broke it into separate files and it's own package to keep things tidy.

Note that some small commands (noop, version) I left behind just because they were small and more... operational).

Also a caveat is that app/commands/ does not have access to Config, so I had to work around that by binding the http client and the env vars. I'm open to better ideas there..

Added a little something to the makefile, in case it eventually gets bigger. Looks like this:
Screen Shot 2021-09-16 at 5 39 44 PM
)

app/main.go Outdated
@@ -50,14 +50,17 @@ type HTTPTransportConfig struct {
KeepAlive time.Duration
}

// SHA256Sums alias for the sha256 sums
type SHA256Sums []string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

made this because I think I need to kong.Bind it too

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why's that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because https://github.com/cashapp/hermit/pull/118/files#diff-54f9129c1a376afcd83728c59ff47e91d9de0b2672d4312179bf28e75846d9d5R18 . and because reflection, this only comes up at runtime. would be good to have some integration test that shells out and actually runs the commands and checks expected results

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, specifically because otherwise you would have an import cycle. I see.

would be good to have some integration test that shells out and actually runs the commands and checks expected results

There are integration tests in the it sub-directory that should exercise this, among other things.

Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

LGTM thanks this is awesome :)

Makefile Show resolved Hide resolved
app/main.go Outdated
@@ -50,14 +50,17 @@ type HTTPTransportConfig struct {
KeepAlive time.Duration
}

// SHA256Sums alias for the sha256 sums
type SHA256Sums []string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why's that?

app/commands/activate.go Outdated Show resolved Hide resolved
@mihai-chiorean mihai-chiorean marked this pull request as ready for review September 17, 2021 17:36
@alecthomas
Copy link
Collaborator

Sorry for the delay, but on consideration I think I'd prefer it if the commands were still contained in the app package as private types. A couple of reasons:

  1. Making these commands a public package makes it part of the API, which is ongoing maintenance burden (this could be rectified by making it an internal/commands package)
  2. The additional indirection of having to add bindings for injected types is unnecessary complexity/fragility.

Would you mind pulling these back in, but in separate files as you have here?

Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

.

app/main.go Outdated
@@ -50,14 +50,17 @@ type HTTPTransportConfig struct {
KeepAlive time.Duration
}

// SHA256Sums alias for the sha256 sums
type SHA256Sums []string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, specifically because otherwise you would have an import cycle. I see.

would be good to have some integration test that shells out and actually runs the commands and checks expected results

There are integration tests in the it sub-directory that should exercise this, among other things.

@mihai-chiorean
Copy link
Contributor Author

Sorry for the delay, but on consideration I think I'd prefer it if the commands were still contained in the app package as private types. A couple of reasons:

  1. Making these commands a public package makes it part of the API, which is ongoing maintenance burden (this could be rectified by making it an internal/commands package)
  2. The additional indirection of having to add bindings for injected types is unnecessary complexity/fragility.

Would you mind pulling these back in, but in separate files as you have here?

yea, when I made the commands package I was hoping it wouldn't have too many side effects. internal/commands could work too. do you have a strong preference on one vs the other?

@alecthomas
Copy link
Collaborator

yea, when I made the commands package I was hoping it wouldn't have too many side effects. internal/commands could work too. do you have a strong preference on one vs the other?

I'd prefer to keep it in app for now.

@alecthomas
Copy link
Collaborator

Thanks for doing this BTW and sorry for the run-around.

@mihai-chiorean
Copy link
Contributor Author

yea, when I made the commands package I was hoping it wouldn't have too many side effects. internal/commands could work too. do you have a strong preference on one vs the other?

I'd prefer to keep it in app for now.

yea, I can do that.

why isn't app in internal/?

@alecthomas
Copy link
Collaborator

why isn't app in internal/?

It's deliberately public to allow Square to have a custom Hermit binary.

app/main.go Outdated Show resolved Hide resolved
@mihai-chiorean
Copy link
Contributor Author

@alecthomas I couldn't figure out how to run it/ tests locally. but I fixed everything and they all pass now.

@alecthomas alecthomas self-requested a review September 22, 2021 03:31
@alecthomas
Copy link
Collaborator

CI got wedged because ubuntu-16.04 was deprecated (which took about a day to determine). I've pushed a fix to master but you'll have to rebase and push for this to get picked up.

@alecthomas
Copy link
Collaborator

The integration tests should be runnable by executing any of the run.sh scripts in the various subdirectories under it/.

@mihai-chiorean
Copy link
Contributor Author

The integration tests should be runnable by executing any of the run.sh scripts in the various subdirectories under it/.

Error: Deactivate Hermit environment before running integration tests this is what I've been fighting trying to run them

@mihai-chiorean
Copy link
Contributor Author

@alecthomas I finally got around to moving this on my laptop where I was able to run the integration tests and make the fixes. mind taking another pass at it?

@alecthomas alecthomas merged commit e86a78f into cashapp:master Sep 30, 2021
@alecthomas
Copy link
Collaborator

LGTM!

@alecthomas
Copy link
Collaborator

Thanks for persisting.

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.

None yet

2 participants