Skip to content

Commit

Permalink
Support version as an URL
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Apr 9, 2022
1 parent 1fb4527 commit 6374adc
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 370 deletions.
11 changes: 5 additions & 6 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
通过命令:`brew install linuxsuren/linuxsuren/hd` 来安装

或者,对于 Linux 用户可以直接通过命令下载:
```
```shell
curl -L https://github.com/linuxsuren/http-downloader/releases/latest/download/hd-linux-amd64.tar.gz | tar xzv
mv hd /usr/local/bin
```
Expand All @@ -20,26 +20,25 @@ mv hd /usr/local/bin

# 用法

```
```shell
hd get https://github.com/jenkins-zh/jenkins-cli/releases/latest/download/jcli-linux-amd64.tar.gz --thread 6
```

或者,用一个更加简便的办法:

```
```shell
hd get jenkins-zh/jenkins-cli/jcli -t 6
```

获取,你也可以安装一个来自 GitHub 的软件包:

```
```shell
hd install jenkins-zh/jenkins-cli/jcli -t 6
```
```

或者,你也可以从 GitHub 上下载预发布的二进制包:

```
```shell
hd get --pre ks
```

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ Want to go through the code? [GitPod](https://gitpod.io/#https://github.com/linu
# Usage

## Download
```
```shell
hd get https://github.com/jenkins-zh/jenkins-cli/releases/latest/download/jcli-linux-amd64.tar.gz --thread 6
```

Or use a simple way instead of typing the whole URL:

```
```shell
hd get jenkins-zh/jenkins-cli/jcli -t 6
```

Or you might want to download a pre-released binary package from GitHub:

```
```shell
hd get --pre ks
```

Expand Down Expand Up @@ -76,7 +76,7 @@ CMD ["ks"]
You can import it from `github.com/linuxsuren/http-downloader/pkg/installer`, then put the following code to your CLI.
It can help you to download desired tools:

```
```go
is := installer.Installer{
Provider: "github",
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ func TestArrayCompletion(t *testing.T) {
array, direct := function(nil, nil, "")
assert.Equal(t, []string{"a", "b"}, array)
assert.Equal(t, cobra.ShellCompDirectiveNoFileComp, direct)
}
}
156 changes: 0 additions & 156 deletions pkg/installer.go

This file was deleted.

15 changes: 15 additions & 0 deletions pkg/installer/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ func (o *Installer) ProviderURLParse(path string, acceptPreRelease bool) (packag
}
}

// parse the version if it's an URL
if cfg.Version != "" && (strings.HasPrefix(cfg.Version, "http://") || strings.HasPrefix(cfg.Version, "https://")) {
var resp *http.Response
if resp, err = http.Get(cfg.Version); err != nil || resp.StatusCode != http.StatusOK {
err = fmt.Errorf("cannot get version from '%s', error is '%v', status code is '%d'", cfg.Version, err, resp.StatusCode)
return
}
var data []byte
if data, err = ioutil.ReadAll(resp.Body); err != nil {
err = fmt.Errorf("failed to get version from '%s', error is '%v'", cfg.Version, err)
return
}
hdPkg.Version = string(data)
}

if cfg.URL != "" {
// it does not come from GitHub release
tmp, _ := template.New("hd").Parse(cfg.URL)
Expand Down
1 change: 1 addition & 0 deletions pkg/installer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type HDConfig struct {
PreInstalls []CmdWithArgs `yaml:"preInstalls"`
PostInstalls []CmdWithArgs `yaml:"postInstalls"`
TestInstalls []CmdWithArgs `yaml:"testInstalls"`
Version string `yaml:"version"`

Org, Repo string
}
Expand Down
15 changes: 0 additions & 15 deletions pkg/net.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/os/apt/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func SetInstallerRegistry(registry core.InstallerRegistry) {
registry.Registry("vim", &vimInstallerInUbuntu{})
registry.Registry("golang", &golangInstallerInUbuntu{})
registry.Registry("git", &gitInstallerInUbuntu{})
registry.Registry("kubectl", &kubectlInstallerInUbuntu{})
registry.Registry("bash-completion", &bashCompletionInstallerInUbuntu{})
registry.Registry("asciinema", &asciinemaInstallerInUbuntu{})
registry.Registry("ffmpge", &ffmpegInstallerInUbuntu{})
Expand Down
102 changes: 0 additions & 102 deletions pkg/os/apt/kubectl.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/os/yum/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ func SetInstallerRegistry(registry core.InstallerRegistry) {
registry.Registry("vim", &vimInstallerInCentOS{})
registry.Registry("golang", &golangInstallerInCentOS{})
registry.Registry("git", &gitInstallerInCentOS{})
registry.Registry("kubectl", &kubectlInstallerInCentOS{})
registry.Registry("bash-completion", &bashCompletionInstallerInCentOS{})
}
Loading

0 comments on commit 6374adc

Please sign in to comment.