Skip to content

Commit

Permalink
Merge pull request #90 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.0.0
  • Loading branch information
andyone authored May 20, 2020
2 parents 8123cd7 + c687508 commit a98a45d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 126 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
language: go

go:
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
- 1.14.x
- tip

os:
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ git-config: ## Configure git redirects for stable import path services
git config --global http.https://pkg.re.followRedirects true

deps: git-config ## Download dependencies
go get -d -v pkg.re/cheggaaa/pb.v1
go get -d -v pkg.re/essentialkaos/ek.v11
go get -d -v pkg.re/essentialkaos/z7.v9
go get -d -v pkg.re/essentialkaos/ek.v12
go get -d -v pkg.re/essentialkaos/zip7.v1

fmt: ## Format source code with gofmt
find . -name "*.go" -exec gofmt -s -w {} \;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="#usage-demo">Usage demo</a> • <a href="#installation">Installation</a> • <a href="#usage">Usage</a> • <a href="#build-status">Build Status</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a>
</p>

`rbinstall` is a utility for installing prebuilt ruby to [rbenv](https://github.com/rbenv/rbenv).
`rbinstall` is a utility for installing prebuilt Ruby to [rbenv](https://github.com/rbenv/rbenv).

### Usage demo

Expand Down
134 changes: 48 additions & 86 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,33 @@ import (
"strings"
"time"

"pkg.re/essentialkaos/ek.v11/env"
"pkg.re/essentialkaos/ek.v11/fmtc"
"pkg.re/essentialkaos/ek.v11/fmtutil"
"pkg.re/essentialkaos/ek.v11/fsutil"
"pkg.re/essentialkaos/ek.v11/hash"
"pkg.re/essentialkaos/ek.v11/knf"
"pkg.re/essentialkaos/ek.v11/log"
"pkg.re/essentialkaos/ek.v11/options"
"pkg.re/essentialkaos/ek.v11/passwd"
"pkg.re/essentialkaos/ek.v11/req"
"pkg.re/essentialkaos/ek.v11/signal"
"pkg.re/essentialkaos/ek.v11/sortutil"
"pkg.re/essentialkaos/ek.v11/strutil"
"pkg.re/essentialkaos/ek.v11/system"
"pkg.re/essentialkaos/ek.v11/terminal"
"pkg.re/essentialkaos/ek.v11/terminal/window"
"pkg.re/essentialkaos/ek.v11/timeutil"
"pkg.re/essentialkaos/ek.v11/tmp"
"pkg.re/essentialkaos/ek.v11/usage"
"pkg.re/essentialkaos/ek.v11/usage/update"
"pkg.re/essentialkaos/ek.v11/version"

knfv "pkg.re/essentialkaos/ek.v11/knf/validators"
knff "pkg.re/essentialkaos/ek.v11/knf/validators/fs"

"pkg.re/essentialkaos/z7.v9"

"pkg.re/cheggaaa/pb.v1"
"pkg.re/essentialkaos/ek.v12/env"
"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/fmtutil"
"pkg.re/essentialkaos/ek.v12/fsutil"
"pkg.re/essentialkaos/ek.v12/hash"
"pkg.re/essentialkaos/ek.v12/knf"
"pkg.re/essentialkaos/ek.v12/log"
"pkg.re/essentialkaos/ek.v12/options"
"pkg.re/essentialkaos/ek.v12/passwd"
"pkg.re/essentialkaos/ek.v12/progress"
"pkg.re/essentialkaos/ek.v12/req"
"pkg.re/essentialkaos/ek.v12/signal"
"pkg.re/essentialkaos/ek.v12/sortutil"
"pkg.re/essentialkaos/ek.v12/strutil"
"pkg.re/essentialkaos/ek.v12/system"
"pkg.re/essentialkaos/ek.v12/terminal"
"pkg.re/essentialkaos/ek.v12/terminal/window"
"pkg.re/essentialkaos/ek.v12/timeutil"
"pkg.re/essentialkaos/ek.v12/tmp"
"pkg.re/essentialkaos/ek.v12/usage"
"pkg.re/essentialkaos/ek.v12/usage/update"
"pkg.re/essentialkaos/ek.v12/version"

knfv "pkg.re/essentialkaos/ek.v12/knf/validators"
knff "pkg.re/essentialkaos/ek.v12/knf/validators/fs"

"pkg.re/essentialkaos/zip7.v1"

"github.com/essentialkaos/rbinstall/index"
)
Expand All @@ -58,7 +57,7 @@ import (
// App info
const (
APP = "RBInstall"
VER = "0.22.0"
VER = "1.0.0"
DESC = "Utility for installing prebuilt Ruby versions to rbenv"
)

Expand Down Expand Up @@ -138,14 +137,6 @@ const (

// ////////////////////////////////////////////////////////////////////////////////// //

// PassThru is reader for progress bar
type PassThru struct {
io.Reader
pb *pb.ProgressBar
}

// ////////////////////////////////////////////////////////////////////////////////// //

var optMap = options.Map{
OPT_REINSTALL: {Type: options.BOOL, Conflicts: OPT_UNINSTALL},
OPT_UNINSTALL: {Type: options.BOOL, Conflicts: OPT_REINSTALL},
Expand Down Expand Up @@ -259,6 +250,13 @@ func configureUI() {
fmtc.DisableColors = true
useRawOutput = true
}

progress.DefaultSettings.BarFgColorTag = "{#161}"
progress.DefaultSettings.NameColorTag = "{*}"
progress.DefaultSettings.PercentColorTag = "{*}"
progress.DefaultSettings.ProgressColorTag = "{s}"
progress.DefaultSettings.SpeedColorTag = "{s}"
progress.DefaultSettings.RemainingColorTag = "{s}"
}

// prepare do some preparations for installing ruby
Expand Down Expand Up @@ -656,10 +654,9 @@ func installCommand(rubyVersion string) {

// //////////////////////////////////////////////////////////////////////////////// //

fmtc.Printf("Fetching {c}%s {s-}(%s){!} from CDN…\n", info.Name, fmtutil.PrettySize(info.Size))
fmtc.Printf("Fetching {*}{#161}%s{!} from CDN…\n", info.Name)

url := knf.GetS(STORAGE_URL) + "/" + info.Path + "/" + info.File
file, err := downloadFile(url, info.File)
file, err := downloadFile(info)

if err != nil {
printErrorAndExit(err.Error())
Expand Down Expand Up @@ -795,10 +792,10 @@ func installCommand(rubyVersion string) {

if aliasCreated {
log.Info("[%s] Installed version %s as %s", currentUser.RealName, info.Name, cleanVersionName)
fmtc.Printf("{g}Version {*}%s{!*} successfully installed as {*}%s{!}\n", info.Name, cleanVersionName)
fmtc.Printf("{#161}Version {*}%s{!*} successfully installed as {*}%s{!}\n", info.Name, cleanVersionName)
} else {
log.Info("[%s] Installed version %s", currentUser.RealName, info.Name)
fmtc.Printf("{g}Version {*}%s{!*} successfully installed{!}\n", info.Name)
fmtc.Printf("{#161}Version {*}%s{!*} successfully installed{!}\n", info.Name)
}
}

Expand Down Expand Up @@ -906,7 +903,7 @@ func unpackTaskHandler(args ...string) (string, error) {
file := args[0]
outputDir := args[1]

output, err := z7.Extract(z7.Props{File: file, OutputDir: outputDir})
output, err := zip7.Extract(zip7.Props{File: file, OutputDir: outputDir})

if err != nil {
unpackError := err
Expand Down Expand Up @@ -1162,14 +1159,15 @@ func updateRubygems(rubyVersion, gemVersion string) error {
}

// downloadFile download file from remote host
func downloadFile(url, fileName string) (string, error) {
func downloadFile(info *index.VersionInfo) (string, error) {
url := knf.GetS(STORAGE_URL) + "/" + info.Path + "/" + info.File
tmpDir, err := temp.MkDir()

if err != nil {
return "", err
}

fd, err := os.OpenFile(tmpDir+"/"+fileName, os.O_CREATE|os.O_WRONLY, 0644)
fd, err := os.OpenFile(tmpDir+"/"+info.File, os.O_CREATE|os.O_WRONLY, 0644)

if err != nil {
return "", err
Expand All @@ -1192,19 +1190,13 @@ func downloadFile(url, fileName string) (string, error) {
if options.GetB(OPT_NO_PROGRESS) {
_, err = io.Copy(fd, resp.Body)
} else {
bar := makeProgressBar(resp.ContentLength)

defer bar.Finish()

pt := &PassThru{
Reader: resp.Body,
pb: bar.Start(),
}

_, err = io.Copy(fd, pt)
pb := progress.New(resp.ContentLength, "")
defer pb.Finish()
pb.Start()
_, err = io.Copy(fd, pb.PassThru(resp.Body))
}

return tmpDir + "/" + fileName, err
return tmpDir + "/" + info.File, err
}

// printCurrentVersionName print version from given slice for
Expand Down Expand Up @@ -1269,23 +1261,6 @@ func printCurrentVersionName(category string, versions index.CategoryData, insta
return false
}

// makeProgressBar create and configure progress bar instance
func makeProgressBar(total int64) *pb.ProgressBar {
bar := pb.New64(total)

bar.ShowCounters = false
bar.BarStart = "—"
bar.BarEnd = " "
bar.Empty = " "
bar.Current = "—"
bar.CurrentN = "→"
bar.Width = 80
bar.ForceWidth = false
bar.RefreshRate = 50 * time.Millisecond

return bar
}

// printSized render format with given size and print text with give arguments
func printSized(format string, size int, a ...interface{}) {
fmtc.Printf(fmtc.Sprintf(format, size), a...)
Expand Down Expand Up @@ -1735,19 +1710,6 @@ func exit(code int) {

// ////////////////////////////////////////////////////////////////////////////////// //

// Read proxy for progress bar
func (pt *PassThru) Read(p []byte) (int, error) {
n, err := pt.Reader.Read(p)

if n > 0 {
pt.pb.Add64(int64(n))
}

return n, err
}

// ////////////////////////////////////////////////////////////////////////////////// //

func showUsage() {
info := usage.NewInfo("", "version")

Expand Down
6 changes: 3 additions & 3 deletions cli/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ package cli
import (
"time"

"pkg.re/essentialkaos/ek.v11/fmtc"
"pkg.re/essentialkaos/ek.v11/options"
"pkg.re/essentialkaos/ek.v11/timeutil"
"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/options"
"pkg.re/essentialkaos/ek.v12/timeutil"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
24 changes: 12 additions & 12 deletions clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"runtime"
"time"

"pkg.re/essentialkaos/ek.v11/fmtc"
"pkg.re/essentialkaos/ek.v11/fmtutil"
"pkg.re/essentialkaos/ek.v11/fsutil"
"pkg.re/essentialkaos/ek.v11/httputil"
"pkg.re/essentialkaos/ek.v11/jsonutil"
"pkg.re/essentialkaos/ek.v11/options"
"pkg.re/essentialkaos/ek.v11/path"
"pkg.re/essentialkaos/ek.v11/req"
"pkg.re/essentialkaos/ek.v11/terminal"
"pkg.re/essentialkaos/ek.v11/timeutil"
"pkg.re/essentialkaos/ek.v11/usage"
"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/fmtutil"
"pkg.re/essentialkaos/ek.v12/fsutil"
"pkg.re/essentialkaos/ek.v12/httputil"
"pkg.re/essentialkaos/ek.v12/jsonutil"
"pkg.re/essentialkaos/ek.v12/options"
"pkg.re/essentialkaos/ek.v12/path"
"pkg.re/essentialkaos/ek.v12/req"
"pkg.re/essentialkaos/ek.v12/terminal"
"pkg.re/essentialkaos/ek.v12/timeutil"
"pkg.re/essentialkaos/ek.v12/usage"

"github.com/essentialkaos/rbinstall/index"
)
Expand All @@ -33,7 +33,7 @@ import (
// App info
const (
APP = "RBInstall Clone"
VER = "0.7.0"
VER = "1.0.0"
DESC = "Utility for cloning RBInstall repository"
)

Expand Down
15 changes: 10 additions & 5 deletions common/rbinstall.spec
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@

Summary: Utility for installing prebuilt Ruby to rbenv
Name: rbinstall
Version: 0.22.0
Version: 1.0.0
Release: 0%{?dist}
Group: Applications/System
License: EKOL
URL: https://github.com/essentialkaos/rbinstall
URL: https://kaos.sh/rbinstall

Source0: https://source.kaos.st/%{name}/%{name}-%{version}.tar.bz2

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

Requires: rbenv ca-certificates p7zip >= 15
Requires: rbenv ca-certificates p7zip >= 16

BuildRequires: golang >= 1.13

Expand All @@ -70,7 +70,7 @@ Utility for installing different prebuilt versions of Ruby to rbenv.
%package gen

Summary: Utility for generating RBInstall index
Version: 0.11.0
Version: 1.0.0
Release: 0%{?dist}
Group: Development/Tools

Expand All @@ -82,7 +82,7 @@ Utility for generating RBInstall index.
%package clone

Summary: Utility for cloning RBInstall repository
Version: 0.7.0
Version: 1.0.0
Release: 0%{?dist}
Group: Development/Tools

Expand Down Expand Up @@ -143,6 +143,11 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Tue May 19 2020 Anton Novojilov <[email protected]> - 1.0.0-0
- [cli|gen|clone] Migrated to ek.v12
- [cli] Using zip7 package instead z7
- [cli] Improved UI

* Thu Jan 16 2020 Anton Novojilov <[email protected]> - 0.22.0-0
- [cli] Improved RubyGems update mechanic

Expand Down
22 changes: 11 additions & 11 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
"strings"
"time"

"pkg.re/essentialkaos/ek.v11/fmtc"
"pkg.re/essentialkaos/ek.v11/fsutil"
"pkg.re/essentialkaos/ek.v11/hash"
"pkg.re/essentialkaos/ek.v11/jsonutil"
"pkg.re/essentialkaos/ek.v11/options"
"pkg.re/essentialkaos/ek.v11/path"
"pkg.re/essentialkaos/ek.v11/sortutil"
"pkg.re/essentialkaos/ek.v11/strutil"
"pkg.re/essentialkaos/ek.v11/timeutil"
"pkg.re/essentialkaos/ek.v11/usage"
"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/fsutil"
"pkg.re/essentialkaos/ek.v12/hash"
"pkg.re/essentialkaos/ek.v12/jsonutil"
"pkg.re/essentialkaos/ek.v12/options"
"pkg.re/essentialkaos/ek.v12/path"
"pkg.re/essentialkaos/ek.v12/sortutil"
"pkg.re/essentialkaos/ek.v12/strutil"
"pkg.re/essentialkaos/ek.v12/timeutil"
"pkg.re/essentialkaos/ek.v12/usage"

"github.com/essentialkaos/rbinstall/index"
)
Expand All @@ -34,7 +34,7 @@ import (
// App info
const (
APP = "RBInstall Gen"
VER = "0.11.0"
VER = "1.0.0"
DESC = "Utility for generating RBInstall index"
)

Expand Down
Loading

0 comments on commit a98a45d

Please sign in to comment.