Skip to content

Commit 50e4847

Browse files
authored
chore: change the entry point to support go install (#56)
1 parent 7197218 commit 50e4847

6 files changed

Lines changed: 44 additions & 5 deletions

File tree

.goreleaser.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ before:
1010
- go mod tidy
1111

1212
builds:
13-
- binary: loops
13+
- main: ./cmd/loops
14+
binary: loops
1415
env:
1516
- CGO_ENABLED=0
1617
goos:

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ To install a specific version or to a custom path, append `-s -- <version> <path
3737
irm https://raw.githubusercontent.com/Loops-so/cli/main/install.ps1 | iex
3838
```
3939

40+
### Go install
41+
42+
```bash
43+
go install github.com/loops-so/cli/cmd/loops@latest
44+
```
45+
4046
## Auth
4147

4248
The CLI requires a Loops API key. Get one from [Settings > API](https://app.loops.so/settings?page=api).

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tasks:
2222
deps:
2323
- deps
2424
cmds:
25-
- go build -o dist/loops
25+
- go build -o dist/loops ./cmd/loops
2626

2727
test:
2828
desc: run tests

main.go renamed to cmd/loops/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/*
2-
Copyright © 2026 Loops <support@loops.so>
3-
*/
41
package main
52

63
import "github.com/loops-so/cli/cmd"

cmd/update_check.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ func upgradeCommand() string {
126126
if isHomebrew() {
127127
return "brew upgrade loops"
128128
}
129+
if isGoInstall() {
130+
return "go install github.com/loops-so/cli/cmd/loops@latest"
131+
}
129132
installDir := binDir()
130133
if runtime.GOOS == "windows" {
131134
if installDir != "" {
@@ -147,6 +150,25 @@ func binDir() string {
147150
return filepath.Dir(exe)
148151
}
149152

153+
func isGoInstall() bool {
154+
dir := binDir()
155+
if dir == "" {
156+
return false
157+
}
158+
if gobin := os.Getenv("GOBIN"); gobin != "" && dir == gobin {
159+
return true
160+
}
161+
gopath := os.Getenv("GOPATH")
162+
if gopath == "" {
163+
home, err := os.UserHomeDir()
164+
if err != nil {
165+
return false
166+
}
167+
gopath = filepath.Join(home, "go")
168+
}
169+
return dir == filepath.Join(gopath, "bin")
170+
}
171+
150172
func isHomebrew() bool {
151173
exe, err := os.Executable()
152174
if err != nil {

cmd/version.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cmd
33
import (
44
"fmt"
55
"io"
6+
"runtime/debug"
7+
"strings"
68

79
"github.com/spf13/cobra"
810
)
@@ -32,5 +34,16 @@ func runVersion(w io.Writer) error {
3234
}
3335

3436
func init() {
37+
if info, ok := debug.ReadBuildInfo(); ok && version == "dev" {
38+
if info.Main.Version != "" && info.Main.Version != "(devel)" {
39+
version = strings.TrimPrefix(info.Main.Version, "v")
40+
}
41+
for _, s := range info.Settings {
42+
if s.Key == "vcs.revision" && len(s.Value) >= 7 {
43+
commit = s.Value[:7]
44+
break
45+
}
46+
}
47+
}
3548
rootCmd.AddCommand(versionCmd)
3649
}

0 commit comments

Comments
 (0)