Skip to content

Commit

Permalink
chore: hide install commands when building for homebrew #9
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie0129 committed Oct 8, 2024
1 parent 0d9b44c commit a7fedaf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions brew.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build brew

package main

var hideInstallCommands = true
7 changes: 4 additions & 3 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export GOOS="${OS}"
export GO111MODULE=on
export GOFLAGS="${GOFLAGS:-} -mod=mod "

printf "# BUILD output: %s\ttarget: %s/%s\tversion: %s\n" \
"${OUTPUT}" "${OS}" "${ARCH}" "${VERSION}"
printf "# BUILD output: %s\ttarget: %s/%s\tversion: %s\ttags: %s\n" \
"${OUTPUT}" "${OS}" "${ARCH}" "${VERSION}" "${GOTAGS:- }"

printf "# BUILD building for "

Expand Down Expand Up @@ -79,11 +79,12 @@ if [ -n "${GIT_COMMIT:-}" ]; then
always_ldflags="${always_ldflags} -X $(go list -m)/pkg/version.GitCommit=${GIT_COMMIT}"
fi

export CGO_CFLAGS="-O2 -target arm64-apple-macos12"
export CGO_CFLAGS="-O2"
export CGO_LDFLAGS="-O2"

go build \
-gcflags="${gogcflags}" \
-tags="${GOTAGS:-}" \
-asmflags="${goasmflags}" \
-ldflags="${always_ldflags} ${goldflags}" \
-o "${OUTPUT}" \
Expand Down
16 changes: 13 additions & 3 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var (
commandGroups = []string{
gBasic,
gAdvanced,
gInstallation,
}
)

Expand Down Expand Up @@ -55,8 +54,6 @@ func NewCommand() *cobra.Command {
cmd.AddCommand(
NewDaemonCommand(),
NewVersionCommand(),
NewInstallCommand(),
NewUninstallCommand(),
NewLimitCommand(),
NewDisableCommand(),
NewSetDisableChargingPreSleepCommand(),
Expand All @@ -67,6 +64,19 @@ func NewCommand() *cobra.Command {
NewSetControlMagSafeLEDCommand(),
)

// If building for non-brew, show install commands.
// If building for brew, hide install commands because brew will handle installation.
if !hideInstallCommands {
cmd.AddGroup(&cobra.Group{
ID: gInstallation,
Title: gInstallation,
})
cmd.AddCommand(
NewInstallCommand(),
NewUninstallCommand(),
)
}

return cmd
}

Expand Down
5 changes: 5 additions & 0 deletions nonbrew.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !brew

package main

var hideInstallCommands = false

0 comments on commit a7fedaf

Please sign in to comment.