Skip to content
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

fix the mod setting when install #362

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ jobs:
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3.0.0
- name: Upgrade upx
run: |
# try to fix https://github.com/jenkins-zh/jenkins-cli/issues/493
wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz
tar xvf upx-3.96-amd64_linux.tar.xz
upx-3.96-amd64_linux/upx -V
sudo mv upx-3.96-amd64_linux/upx $(which upx)
upx -V
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4.1.1
with:
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Upgrade upx
run: |
# try to fix https://github.com/jenkins-zh/jenkins-cli/issues/493
wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz
tar xvf upx-3.96-amd64_linux.tar.xz
upx-3.96-amd64_linux/upx -V
sudo mv upx-3.96-amd64_linux/upx $(which upx)
rm -rf upx-3.96-amd64_linux
rm -rf xvf upx-3.96-amd64_linux.tar.xz
upx -V
- name: Image Registry Login
run: |
docker login --username ${{ secrets.DOCKER_HUB_USER }} --password ${{secrets.DOCKER_HUB_TOKEN}}
Expand Down
3 changes: 0 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ builds:
goarch: arm64
- goos: darwin
goarch: arm
hooks:
post:
- upx "{{ .Path }}"
ldflags:
- -X github.com/linuxsuren/cobra-extension/version.version={{.Version}}
- -X github.com/linuxsuren/cobra-extension/version.commit={{.ShortCommit}}
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ Want to go through the code? [GitPod](https://gitpod.io/#https://github.com/linu

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

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

```shell
hd get jcli
hd get mde
```

Or you might want to download a pre-released binary package from GitHub:
Expand All @@ -54,7 +54,8 @@ hd get --pre ks
You can also install a package from GitHub:

```shell
hd install jcli -t 6
#!title: Install mde with specific threads
hd install mde -t 6
```

or install by a category name:
Expand Down
13 changes: 10 additions & 3 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ func newGetCmd(ctx context.Context) (cmd *cobra.Command) {
flags := cmd.Flags()
opt.addFlags(flags)
opt.addPlatformFlags(flags)
opt.addDownloadFlags(flags)
flags.StringVarP(&opt.Output, "output", "o", "", "Write output to <file> instead of stdout.")
flags.BoolVarP(&opt.AcceptPreRelease, "accept-preRelease", "", false,
"If you accept preRelease as the binary asset from GitHub")
flags.BoolVarP(&opt.AcceptPreRelease, "pre", "", false,
"Same with option --accept-preRelease")
flags.BoolVarP(&opt.Force, "force", "f", false, "Overwrite the exist file if this is true")
flags.IntVarP(&opt.Mod, "mod", "", -1, "The file permission, -1 means using the system default")
flags.BoolVarP(&opt.SkipTLS, "skip-tls", "k", false, "Skip the TLS")

flags.DurationVarP(&opt.Timeout, "timeout", "", 15*time.Minute,
`The default timeout in seconds with the HTTP request`)
Expand Down Expand Up @@ -143,6 +142,11 @@ const (
ProviderGitee = "gitee"
)

func (o *downloadOption) addDownloadFlags(flags *pflag.FlagSet) {
flags.IntVarP(&o.Mod, "mod", "", -1, "The file permission, -1 means using the system default")
flags.BoolVarP(&o.SkipTLS, "skip-tls", "k", false, "Skip the TLS")
}

func (o *downloadOption) fetch() (err error) {
if !o.Fetch {
o.wait.Add(1)
Expand Down Expand Up @@ -331,7 +335,10 @@ func (o *downloadOption) runE(cmd *cobra.Command, args []string) (err error) {

// set file permission
if o.Mod != -1 {
err = sysos.Chmod(o.Output, fs.FileMode(o.Mod))
logger.Printf("Setting file permission to %d", o.Mod)
if err = sysos.Chmod(o.Output, fs.FileMode(o.Mod)); err != nil {
return
}
}

if err == nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Cannot find your desired package? Please run command: hd fetch --reset, then try
flags := cmd.Flags()
opt.addFlags(flags)
opt.addPlatformFlags(flags)
opt.addDownloadFlags(flags)
flags.StringVarP(&opt.Category, "category", "c", "",
"The category of the potentials packages")
flags.BoolVarP(&opt.ShowProgress, "show-progress", "", true, "If show the progress of download")
Expand Down
2 changes: 1 addition & 1 deletion pkg/net/multi_thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (d *MultiThreadDownloader) Download(targetURL, targetFilePath string, threa

// concat all these partial files
var f *os.File
if f, err = os.OpenFile(targetFilePath, os.O_CREATE|os.O_WRONLY, 0600); err == nil {
if f, err = os.Create(targetFilePath); err == nil {
defer func() {
_ = f.Close()
}()
Expand Down