-
Notifications
You must be signed in to change notification settings - Fork 453
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 help system to Makefile + FDM command #25028
base: main
Are you sure you want to change the base?
Conversation
Makefile
Outdated
BINS_TO_BUILD = fleet fleetctl | ||
ifdef FLEET | ||
BINS_TO_BUILD = fleet | ||
else ifdef FLEETCTL | ||
BINS_TO_BUILD = fleetctl | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow building either fleet or fleetctl or both, all through the build
command (so you can do fdm build --fleet
or fdm build --fleetctl
, or just fdm build
to do both)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #25028 +/- ##
==========================================
- Coverage 63.59% 63.58% -0.01%
==========================================
Files 1619 1619
Lines 154976 154995 +19
Branches 4038 4038
==========================================
+ Hits 98552 98559 +7
- Misses 48654 48662 +8
- Partials 7770 7774 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pulled this down and there's no obvious way to get the longer help text while running make
. Probably just missing something but e.g. "make help build" shows help and then builds, rather than help
consuming all arguments to show the right thing.
Guessing make fdm
fixes this but it's not listed in the help, and the symlink fails:
~/code/fleet fdm $ make fdm
go build -o build/fdm ./tools/fdm
ln -sf "$(pwd)/build/fdm" /usr/local/bin/fdm
ln: /usr/local/bin/fdm: Permission denied
make: *** [fdm] Error 1
Makefile
Outdated
.help-long--build: | ||
@echo "Builds the specified binaries (defaults to building fleet and fleetctl)" | ||
.help-options--build: | ||
@echo "FLEET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work all-caps? I've only ever used e.g. make fleetctl
.
Makefile
Outdated
test: lint test-go test-js | ||
|
||
.help-short--generate: | ||
@echo "Generate and bundle required all code" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we're moving this around, probably better to revise this description to be more accurate, as we have a bunch of generate commands and this only builds bindata on the go side (vs. commands that update mocks, schema, etc.)
Makefile
Outdated
generate-dev: .prefix | ||
NODE_ENV=development yarn run webpack --progress | ||
go run github.com/kevinburke/go-bindata/go-bindata -debug -pkg=bindata -tags full \ | ||
-o=server/bindata/generated.go \ | ||
frontend/templates/ assets/... server/mail/templates | ||
NODE_ENV=development yarn run webpack --progress --watch | ||
|
||
.help-short--generate-mock: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're actively working on this PR, mind making the tweaks mentioned in this Slack thread on command naming?
Ha, adding help for the Getting long help with |
@iansltx circled back to this with some updates. I did a bit of a refactor to allow positional arguments in commands, so you can now do e.g.
or
Positional arguments are added to the
but obviously the idea is to have I also simplified the
When it comes to actually building binaries, |
make generate-doc | ||
make doc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per discussion here, this PR changes the Makefile targets:
- generate-doc -> doc
- generate-mock -> mock
- dump-test-schema -> test-schema
The old targets are still there as aliases.
DEFAULT_PKG_TO_TEST := ./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/... | ||
ifeq ($(CI_TEST_PKG), main) | ||
CI_PKG_TO_TEST=$(shell go list ${DEFAULT_PKG_TO_TEST} | grep -v "server/datastore/mysql" | grep -v "cmd/fleetctl" | grep -v "server/vulnerabilities" | sed -e 's|github.com/fleetdm/fleet/v4/||g') | ||
else ifeq ($(CI_TEST_PKG), integration) | ||
CI_PKG_TO_TEST="server/service" | ||
else ifeq ($(CI_TEST_PKG), mysql) | ||
CI_PKG_TO_TEST="server/datastore/mysql/..." | ||
else ifeq ($(CI_TEST_PKG), fleetctl) | ||
CI_PKG_TO_TEST="cmd/fleetctl/..." | ||
else ifeq ($(CI_TEST_PKG), vuln) | ||
CI_PKG_TO_TEST="server/vulnerabilities/..." | ||
else | ||
CI_PKG_TO_TEST=$(DEFAULT_PKG_TO_TEST) | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this down next to the test-go
target.
ci-pkg-list: | ||
@echo $(CI_PKG_TO_TEST) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dantecatalfamo I think this was just for debugging?
.help-short--test-go: | ||
@echo "Run Go tests for CI" | ||
.help-long--test-go: | ||
@echo "Run one or more bundle of Go tests. These are bundled together to try and make CI testing more parallelizable (and thus faster)." | ||
.help-options--test-go: | ||
@echo "CI_TEST_PKG=[test package]" | ||
@echo "The test package bundle to run. If not specified, all Go tests will run." | ||
.help-extra--test-go: | ||
@echo "AVAILABLE TEST BUNDLES:" | ||
@echo " integration" | ||
@echo " mysql" | ||
@echo " fleetctl" | ||
@echo " vuln" | ||
@echo " main (all tests not included in other bundles)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Print separators between help sections. | ||
.help-sep-1: | ||
@printf "\036" | ||
.help-sep-2: | ||
@printf "\036" | ||
.help-sep-3: | ||
@printf "\036" | ||
.help-sep-4: | ||
@printf "\036" | ||
.help-sep-5: | ||
@printf "\036" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get make
to repeat the same target no matter what I tried, so I just added multiple targets that do the same thing. See makehelp.sh
for where they're used.
This PR adds a help system to the current Fleet Makefile to make it easier to add and maintain documentation for the various commands it contains. For any command
foo
in the Makefile, various targets can be added to provide help:.help-short--foo
: print a terse description of the command, e.g. "build the binaries". This will be used both in the main help output which lists all available commands, and in the individual command help..help-long--foo
: print a longer description of the command, e.g. "Builds the specified binaries (defaults to building fleet and fleetctl)". Can be multi-line..help-options--foo
: print options for the command as pairs of lines, with the first line being the option name (i.e. the makefile var name) and the second being a description of the option. For the "build" command, we output:The
.help-long
and.help-options
variants are mainly for use with the newfdm
command (see below), but can also be utilized inmake
invocations using theSPECIFIC_CMD
var, e.g.make help SPECIFIC_CMD=build
.The
fdm
commandThis PR also introduces a new
fdm
utility that wraps the makefile and translates arguments to the various targets into more idiomatic CLI arguments; for examplecan be called with
fdm help
will list all commands that have at least.help-short-
targets. I'd advise doing this for developer-facing commands likebuild
. In the future we can provide a similar mechanism for adding help to more esoteric commands likenudge-app-tar-gz
and make the full command list available via something likefdm help --all
.fdm help <command>
will output full help for a command, e.g.fdm help build
gives you:The
fdm
command can be built withmake fdm
, which also symlinks it into/usr/local/bin
for ease of use.