Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Mar 6, 2024
1 parent 602866f commit 7f05ae9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 56 deletions.
8 changes: 6 additions & 2 deletions common/init-exporter-converter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Summary: Utility for converting init-exporter procfiles from v1 to v2 format
Name: init-exporter-converter
Version: 0.12.0
Version: 0.12.1
Release: 0%{?dist}
Group: Development/Tools
License: MIT
Expand All @@ -16,7 +16,7 @@ Source0: %{name}-%{version}.tar.gz

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

BuildRequires: golang >= 1.19
BuildRequires: golang >= 1.20

Provides: %{name} = %{version}-%{release}

Expand Down Expand Up @@ -60,6 +60,10 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Wed Mar 06 2024 Anton Novojilov <[email protected]> - 0.12.1-0
- Dependencies update
- Code refactoring

* Fri Mar 10 2023 Anton Novojilov <[email protected]> - 0.12.0-0
- Added verbose version output
- Dependencies update
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.18
require (
github.com/essentialkaos/ek/v12 v12.102.0
github.com/essentialkaos/go-simpleyaml/v2 v2.1.4
github.com/funbox/init-exporter v0.25.0
github.com/funbox/init-exporter v0.25.1
)

require (
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ github.com/essentialkaos/ek/v12 v12.102.0 h1:frHp1+iElQUg4CoscVQWuVFY1QZvU0fIqAa
github.com/essentialkaos/ek/v12 v12.102.0/go.mod h1:T5RaDwmg6aso4vPfMp9OSk0R5YAjGtkinlxj2kDXUbo=
github.com/essentialkaos/go-simpleyaml/v2 v2.1.4 h1:B2bXdGWaQ6Xy3HTsO2DLBoNV7cbMW3KDmeeOKYLo9z0=
github.com/essentialkaos/go-simpleyaml/v2 v2.1.4/go.mod h1:pVQTleUBC8xBI9+HnTF38xWBZqANNrmMAzwmUemblJg=
github.com/funbox/init-exporter v0.25.0 h1:deCskPMq6KmzT6fSOqhYCsumFZiFKWp63eI1sHke6AQ=
github.com/funbox/init-exporter v0.25.0/go.mod h1:WFmUTcRPH4shVWFw16UtjJY5JeU1QC5wAPEzMpCWYH0=
github.com/funbox/init-exporter v0.25.1 h1:xmvgrPFUPInBsZRSSB8+mMciUtw78HFN0fCeMZuRyKo=
github.com/funbox/init-exporter v0.25.1/go.mod h1:r1uzN8W6j8P5awNYmWkQNA+EpIGEKdYrGA8IGVBleN4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
64 changes: 16 additions & 48 deletions init-exporter-converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"runtime"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/knf"
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
"github.com/essentialkaos/ek/v12/usage/completion/fish"
Expand All @@ -34,7 +32,7 @@ import (
// App props
const (
APP = "init-exporter-converter"
VER = "0.12.0"
VER = "0.12.1"
DESC = "Utility for converting procfiles from v1 to v2 format"
)

Expand Down Expand Up @@ -130,24 +128,7 @@ func main() {

// preConfigureUI preconfigures UI based on information about user terminal
func preConfigureUI() {
term := os.Getenv("TERM")

fmtc.DisableColors = true

if term != "" {
switch {
case strings.Contains(term, "xterm"),
strings.Contains(term, "color"),
term == "screen":
fmtc.DisableColors = false
}
}

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
fmtc.DisableColors = true
}

if os.Getenv("NO_COLOR") != "" {
if !tty.IsTTY() {
fmtc.DisableColors = true
}
}
Expand Down Expand Up @@ -237,7 +218,7 @@ func convert(file string) error {
}

if !options.GetB(OPT_IN_PLACE) {
fmt.Printf(yamlData)
fmt.Print(yamlData)
return nil
}

Expand Down Expand Up @@ -349,19 +330,14 @@ func validateYaml(data string) error {

// writeData writes procfile data to file
func writeData(file, data string) error {
return ioutil.WriteFile(file, []byte(data), 0644)
return os.WriteFile(file, []byte(data), 0644)
}

// printError prints error message to console
func printError(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...)
}

// printError prints warning message to console
func printWarn(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{y}"+f+"{!}\n", a...)
}

// printErrorAndExit print error message and exit with exit code 1
func printErrorAndExit(f string, a ...interface{}) {
printError(f, a...)
Expand All @@ -376,11 +352,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "init-exporter-converter"))
fmt.Print(bash.Generate(info, "init-exporter-converter"))
case "fish":
fmt.Printf(fish.Generate(info, "init-exporter-converter"))
fmt.Print(fish.Generate(info, "init-exporter-converter"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "init-exporter-converter"))
fmt.Print(zsh.Generate(info, optMap, "init-exporter-converter"))
default:
return 1
}
Expand All @@ -390,12 +366,7 @@ func printCompletion() int {

// printMan prints man page
func printMan() {
fmt.Println(
man.Generate(
genUsage(),
genAbout(""),
),
)
fmt.Println(man.Generate(genUsage(), genAbout("")))
}

// genUsage generates usage info
Expand Down Expand Up @@ -426,16 +397,13 @@ func genUsage() *usage.Info {
// genAbout generates info about version
func genAbout(gitRev string) *usage.About {
about := &usage.About{
App: APP,
Version: VER,
Desc: DESC,
Year: 2006,
Owner: "FunBox",
License: "MIT License",
UpdateChecker: usage.UpdateChecker{
"funbox/init-exporter-converter",
update.GitHubChecker,
},
App: APP,
Version: VER,
Desc: DESC,
Year: 2006,
Owner: "FunBox",
License: "MIT License",
UpdateChecker: usage.UpdateChecker{"funbox/init-exporter-converter", update.GitHubChecker},

AppNameColorTag: "{*}" + colorTagApp,
VersionColorTag: colorTagVer,
Expand Down

0 comments on commit 7f05ae9

Please sign in to comment.