Skip to content

Commit 055f328

Browse files
authored
Merge pull request #141 from legendu-net/dev
Merge dev into main
2 parents fa804f4 + 524b1de commit 055f328

File tree

12 files changed

+105
-77
lines changed

12 files changed

+105
-77
lines changed

cmd/dev/bytehound.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func bytehound(cmd *cobra.Command, args []string) {
1616
case "linux":
1717
network.DownloadGitHubRelease("koute/bytehound", "", map[string][]string{
1818
"common": {"bytehound", "tgz"},
19-
"x86_64": {"x86_64"},
19+
"amd64": {"x86_64"},
2020
"linux": {"linux", "gnu"},
2121
}, []string{}, "/tmp/bytehound.tar.gz")
2222
command := utils.Format(`mkdir -p ~/.local/bin && tar -zxvf /tmp/bytehound.tar.gz -C ~/.local/bin \

cmd/dev/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func installGitUi(cmd *cobra.Command) {
6161
"common": {"tar.gz"},
6262
"linux": {"linux"},
6363
"darwin": {"mac"},
64-
"x86_64": {"musl"},
64+
"amd64": {"musl"},
6565
"arm64": {"aarch64"},
6666
}, []string{}, file)
6767
command := utils.Format(`{prefix} tar -zxvf {file} -C /usr/local/bin/`, map[string]string{
@@ -100,7 +100,7 @@ func installGitDelta(cmd *cobra.Command) {
100100
file := filepath.Join(tmpdir, "git-delta.tar.gz")
101101
network.DownloadGitHubRelease("dandavison/delta", "", map[string][]string{
102102
"common": {},
103-
"x86_64": {"x86_64"},
103+
"amd64": {"x86_64"},
104104
"arm64": {"aarch64"},
105105
"linux": {"linux", "gnu"},
106106
"darwin": {"apple", "darwin"},

cmd/dev/golang.go

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"path/filepath"
77
"regexp"
88
"runtime"
9-
"strings"
109

1110
"github.com/spf13/cobra"
1211
"golang.org/x/sys/unix"
@@ -27,6 +26,33 @@ func getGolangVersion() string {
2726
return re.FindStringSubmatch(html)[1]
2827
}
2928

29+
func installGoLang(prefix string) {
30+
url := utils.Format("https://go.dev/dl/go{ver}.{os}-{arch}.tar.gz", map[string]string{
31+
"ver": getGolangVersion(),
32+
"os": runtime.GOOS,
33+
"arch": utils.HostKernelArch(),
34+
})
35+
goTgz := utils.DownloadFile(url, "go_*.tar.gz", true)
36+
cmd := utils.Format(`{prefix} rm -rf /usr/local/go \
37+
&& {prefix} tar -C /usr/local/ -xzf {goTgz}\
38+
&& {prefix} rm -rf /usr/local/go/pkg/*/cmd`,
39+
map[string]string{
40+
"prefix": prefix,
41+
"goTgz": goTgz,
42+
},
43+
)
44+
utils.RunCmd(cmd)
45+
}
46+
47+
func installGoLangCiLint(prefix string) {
48+
script := "https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh"
49+
cmd := utils.Format(`curl -sSfL {script} | {prefix} sh -s -- -b /usr/local/bin`, map[string]string{
50+
"script": script,
51+
"prefix": prefix,
52+
})
53+
utils.RunCmd(cmd)
54+
}
55+
3056
// Install and configure Golang.
3157
func golang(cmd *cobra.Command, args []string) {
3258
prefix := utils.GetCommandPrefix(false, map[string]uint32{
@@ -36,27 +62,9 @@ func golang(cmd *cobra.Command, args []string) {
3662
})
3763
if utils.GetBoolFlag(cmd, "install") {
3864
switch runtime.GOOS {
39-
case "windows":
40-
case "darwin":
41-
utils.BrewInstallSafe([]string{"go"})
42-
case "linux":
43-
ver := getGolangVersion()
44-
url := strings.ReplaceAll("https://go.dev/dl/go{ver}.linux-amd64.tar.gz", "{ver}", ver)
45-
goTgz := utils.DownloadFile(url, "go_*.tar.gz", true)
46-
cmd := utils.Format(`{prefix} rm -rf /usr/local/go \
47-
&& {prefix} tar -C /usr/local/ -xzf {goTgz}\
48-
&& {prefix} rm -rf /usr/local/go/pkg/*/cmd \
49-
/usr/local/go/pkg/bootstrap \
50-
/usr/local/go/pkg/obj \
51-
/usr/local/go/pkg/tool/*/api \
52-
/usr/local/go/pkg/tool/*/go_bootstrap \
53-
/usr/local/go/src/cmd/dist/dist`,
54-
map[string]string{
55-
"prefix": prefix,
56-
"goTgz": goTgz,
57-
},
58-
)
59-
utils.RunCmd(cmd)
65+
case "darwin", "linux":
66+
installGoLang(prefix)
67+
installGoLangCiLint(prefix)
6068
default:
6169
log.Fatal("The OS ", runtime.GOOS, " is not supported!")
6270
}

cmd/dev/pytype.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ func pytype(cmd *cobra.Command, args []string) {
2121
if utils.GetBoolFlag(cmd, "config") {
2222
srcFile := "data/pytype/pyproject.toml"
2323
var srcMap orderedmap.OrderedMap[string, any]
24-
toml.Unmarshal(utils.ReadEmbeddedFile(srcFile), &srcMap)
24+
err := toml.Unmarshal(utils.ReadEmbeddedFile(srcFile), &srcMap)
25+
if err != nil {
26+
log.Fatalf("Failed to parse TOML: %v", err)
27+
}
2528
destFile := filepath.Join(utils.GetStringFlag(cmd, "dest-dir"), "pyproject.toml")
2629
var destMap orderedmap.OrderedMap[string, any]
2730
if utils.ExistsFile(destFile) {
28-
toml.Unmarshal(utils.ReadFile(destFile), &destMap)
31+
err := toml.Unmarshal(utils.ReadFile(destFile), &destMap)
32+
if err != nil {
33+
log.Fatalf("Failed to parse TOML: %v", err)
34+
}
2935
utils.UpdateMap(destMap, srcMap)
3036
} else {
3137
destMap = srcMap

cmd/dev/rust.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func installSccache() {
6969
file := filepath.Join(tmpdir, "sccache.tar.gz")
7070
network.DownloadGitHubRelease("mozilla/sccache", "", map[string][]string{
7171
"common": {"tar.gz"},
72-
"x86_64": {"x86_64"},
72+
"amd64": {"x86_64"},
7373
"arm64": {"aarch64"},
7474
"linux": {"unknown", "linux", "musl"},
7575
"darwin": {"apple", "darwin"},
@@ -89,7 +89,7 @@ func installCargoBinstall() {
8989
file := filepath.Join(tmpdir, "cargo-binstall.tgz")
9090
network.DownloadGitHubRelease("cargo-bins/cargo-binstall", "", map[string][]string{
9191
"common": {"tgz"},
92-
"x86_64": {"x86_64"},
92+
"amd64": {"x86_64"},
9393
"arm64": {"aarch64"},
9494
"linux": {"unknown", "linux", "gnu"},
9595
"darwin": {"apple", "darwin"},

cmd/network/github.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ func assetNameContainKeywords(name string, keywords []string, keyworkdsExclude [
5858
func filterReleases(url string, constraint string) ReleaseInfo {
5959
log.Printf("Extracting release from %s with the constraint %s", url, constraint)
6060
var releases []ReleaseInfo
61-
json.Unmarshal(utils.HttpGetAsBytes(url, 3, 120), &releases)
61+
err := json.Unmarshal(utils.HttpGetAsBytes(url, 3, 120), &releases)
62+
if err != nil {
63+
log.Fatalf("Failed to parse TOML: %v", err)
64+
}
6265
c := version.NewConstrainGroupFromString(constraint)
6366
for _, release := range releases {
6467
if c.Match(release.TagName) {

cmd/root.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"log"
45
"os"
56

67
"github.com/spf13/cobra"
@@ -42,13 +43,25 @@ $ icon completion fish > ~/.config/fish/completions/icon.fish
4243
Run: func(cmd *cobra.Command, args []string) {
4344
switch args[0] {
4445
case "bash":
45-
cmd.Root().GenBashCompletion(os.Stdout)
46+
err := cmd.Root().GenBashCompletion(os.Stdout)
47+
if err != nil {
48+
log.Fatalf("Failed to generate completion script for bash: %v", err)
49+
}
4650
case "zsh":
47-
cmd.Root().GenZshCompletion(os.Stdout)
51+
err := cmd.Root().GenZshCompletion(os.Stdout)
52+
if err != nil {
53+
log.Fatalf("Failed to generate completion script for bash: %v", err)
54+
}
4855
case "fish":
49-
cmd.Root().GenFishCompletion(os.Stdout, true)
56+
err := cmd.Root().GenFishCompletion(os.Stdout, true)
57+
if err != nil {
58+
log.Fatalf("Failed to generate completion script for bash: %v", err)
59+
}
5060
case "powershell":
51-
cmd.Root().GenPowerShellCompletion(os.Stdout)
61+
err := cmd.Root().GenPowerShellCompletion(os.Stdout)
62+
if err != nil {
63+
log.Fatalf("Failed to generate completion script for bash: %v", err)
64+
}
5265
}
5366
},
5467
}

cmd/shell/fish.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ func downloadFishFromGitHub(version string) string {
1616
output := "/tmp/_fish_shell.tar.xz"
1717
network.DownloadGitHubRelease("fish-shell/fish-shell", version, map[string][]string{
1818
"common": {"fish", "tar.xz"},
19-
"x86_64": {"x86_64"},
19+
"amd64": {"x86_64"},
2020
"arm64": {"aarch64"},
21+
"linux": {"linux"},
2122
"DebianUbuntuSeries": {},
2223
"FedoraSeries": {},
2324
"OtherLinux": {},

cmd/shell/hyper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func downloadHyperFromGitHub(version string) string {
1414
output := "/tmp/_hyper_js_terminal"
1515
network.DownloadGitHubRelease("vercel/hyper", version, map[string][]string{
1616
"common": {},
17-
"x86_64": {"amd64"},
17+
"amd64": {"amd64"},
1818
"arm64": {"arm64"},
1919
"DebianUbuntuSeries": {"deb"},
2020
"FedoraSeries": {"rpm"},

cmd/shell/nushell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func downloadNushellFromGitHub(version string) string {
1616
"common": {"tar.gz"},
1717
"linux": {"unknown", "linux", "gnu"},
1818
"darwin": {"apple", "darwin"},
19-
"x86_64": {"x86_64"},
19+
"amd64": {"x86_64"},
2020
"arm64": {"aarch64"},
2121
}, []string{}, output)
2222
return output

0 commit comments

Comments
 (0)