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

buffalo/cmd/build: forward flags to original main #1492

merged 3 commits into from Dec 10, 2018


None yet
2 participants

rjeczalik commented Dec 6, 2018

Currently it is not possible to pass command line flags to a binary generated by buffalo build. User can face this problem when trying to parse flags in the main function, passing any extra flags on the command line breaks buffalo in different ways:

$ ./my-buffalo-app -my-flag value
ERRO[0001] Error: unknown command "value" for "buffalo"
2018/12/06 14:57:43 exit status 255
$ ./my-buffalo-app -my-flag=value

ERRO[0001] Error: unknown shorthand flag: 'm' in -my-flag=value
2018/12/06 14:56:34 exit status 255
$ ./my-buffalo-app -- -my-flag=value
(displays usage and exists with 0)

I propose making it possible to pass custom arguments to the user's main by respecting the -- delimiter. In particular it would change the behaviour of 3rd example from the above - by executing /my-buffalo-app -- -my-flag=value buffalo is going to pass anything after the -- delimiter to the user's main, that's -my-flag=value.

This PR introduces this change, however it would be good to teach buffalo dev to also understand the -- delimiter, so the following:

$ buffalo dev -- -my-flag=value

Works the same as:

$ buffalo build
$ ./bin/my-buffalo-app -- -my-flag=value


@rjeczalik rjeczalik requested a review from gobuffalo/core-managers as a code owner Dec 6, 2018

@rjeczalik rjeczalik force-pushed the rjeczalik:development branch from 4003d3c to 2c99637 Dec 9, 2018

rjeczalik added some commits Dec 6, 2018

buffalo/cmd/build: forward flags to original main
This PR makes buffalo pass flags after -- delimiter to the original
main. In effect, binaries generated by `buffalo build` can define their
own custom flags. In particular executing:

    $ ./bin/my-web-app -- -h -p 8080

Will forward "-h -p 8080" to the original main function.
buffalo/cmd/dev: forward flags to generated binary
This PR forwards flags passed to `buffalo dev` to the generated binary
upon execution. In particular the following:

    $ buffalo dev -- -h -p 8080

Will pass the "-- -h -p 8080" flags. This is the same
behaviour as executing the following commands:

    $ buffalo build
    $ ./bin/my-web-app -- -h -p 8080

@rjeczalik rjeczalik force-pushed the rjeczalik:development branch from 2c99637 to b2bf5c4 Dec 9, 2018


This comment has been minimized.

rjeczalik commented Dec 9, 2018

For the completeness I've added support for custom flags to the buffalo dev command, so the following:

$ buffalo dev -- -my-flag=value

Behaves exactly as:

$ buffalo build
$ ./bin/my-buffalo-app -- -my-flag=value

@markbates markbates added this to the v0.14.0 milestone Dec 10, 2018

@markbates markbates merged commit ce68c39 into gobuffalo:development Dec 10, 2018

2 checks passed

code-analysis/fixme The Fixmie analysis has finished
continuous-integration/travis-ci/pr The Travis CI build passed

This comment has been minimized.


markbates commented Dec 10, 2018


@rjeczalik rjeczalik deleted the rjeczalik:development branch Dec 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment