gruntwork-io / git-xargs

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
https://blog.gruntwork.io/introducing-git-xargs-an-open-source-tool-to-update-multiple-github-repos-753f9f3675ec
Apache License 2.0
935 stars 62 forks source link

Refactor project layout for better go build and get ergonomics #20

Closed zackproser closed 3 years ago

zackproser commented 3 years ago

Fixes https://github.com/gruntwork-io/git-xargs/issues/18 Fixes #7

@mmlb Please have a look and let me know if this is what you had in mind. Thanks!

Updates project layout which will allow for installing git-xargs with a single call to go get github.com/gruntwork-io/git-xargs.

zackproser commented 3 years ago

Do you also need to update https://github.com/gruntwork-io/git-xargs/blob/master/.circleci/config.yml?

Yes, thank you! Done in 8af5012

mmlb commented 3 years ago

Fixes #18

@mmlb Please have a look and let me know if this is what you had in mind. Thanks!

Yep, thanks.

sc250024 commented 3 years ago

This is needed in addition to the small PR that I just merged: https://github.com/gruntwork-io/git-xargs/pull/14. I realized that after it was merged.

If you now run go get -u -v github.com/gruntwork-io/git-xargs/cmd against https://github.com/gruntwork-io/git-xargs/releases/tag/v0.0.4, it "works", but the binary is now cmd :D

Example:

$ cmd --help                                                                                                

Usage: cmd [--loglevel] [--github-org] [--dry-run] [--skip-pull-requests] [--repo] [--repos] [--branch-name]
[--commit-message] [--pull-request-title] [--pull-request-description] [--help] command [options] [args]

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Commands:

   help, h  Shows a list of commands or help for one command

$ which cmd

/Users/<my-user>/go/bin/cmd
sc250024 commented 3 years ago

Why is the folder called cmd in the first place?

In our other CLI tools, we typically put main.go in the root of the repo, and the packages it depends on within folders. There might be a package called, say, cli or cmd that contains the core logic for parsing CLI args and executing code, a git package for the Git functionality, and so on.

If we put main.go in the root, would calling go get github.com/gruntwork-io/git-xargs do what we want?

@brikis98 I've seen both patterns. Some repos do what you mention, and some put it in cmd/<name-of-binary>. Here's some examples:

Both work, it's just a matter of preference.

zackproser commented 3 years ago

Why is the folder called cmd in the first place?

In our other CLI tools, we typically put main.go in the root of the repo, and the packages it depends on within folders. There might be a package called, say, cli or cmd that contains the core logic for parsing CLI args and executing code, a git package for the Git functionality, and so on.

If we put main.go in the root, would calling go get github.com/gruntwork-io/git-xargs do what we want?

@brikis98 Raised this discussion internally yesterday - the cmd folder originally came from this layout: https://github.com/golang-standards/project-layout#cmd and then we carried that to certain projects including kubergrunt.

That said, it's not required, and personally I'd prefer to drop the cmd path entirely - because the other reason this is tripping some folks up is that they're used to being able to check out a repo and run go build in the root, which you also can't currently do.

I agree calling go get github.com/gruntwork-io/git-xargs would be the ideal.

mmlb commented 3 years ago

Dropping the cmd/ subfolder entirely works for me too, I was mostly interested in not having a binary named cmd in my GOPATH :smile:

zackproser commented 3 years ago

Rearranged everything so that:

@brikis98 @yorinasub17 please have a look when you have time

zackproser commented 3 years ago

@brikis98 Feedback implemented. Thank you!

zackproser commented 3 years ago

Need to dig into test failures.

brikis98 commented 3 years ago

Don't forget to pull in the latest from master and merging it, since all the file paths have changed!

zackproser commented 3 years ago

Don't forget to pull in the latest from master and merging it, since all the file paths have changed!

Did thanks - rebased and now have it all passing again @brikis98 :pray:

zackproser commented 3 years ago

Thanks for the reviews! Going to merge this in now.

yermulnik commented 3 years ago

Was looking forward for this to be merged so that go get … can be used to install binary, but it seems like that it hasn't been released yet so that go get … doesn't do the thing yet — what is the ETA for this feature to be released please?

yermulnik commented 3 years ago

Oh, nevermind me — have just seen v0.0.5 was released :partying_face: