Skip to content

Commit

Permalink
Merge pull request #33 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.5.1
  • Loading branch information
andyone authored Dec 4, 2020
2 parents 5c64f1d + 7b75759 commit be8e358
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 1.3.0 using next command:
# This Makefile generated by GoMakeGen 1.3.2 using next command:
# gomakegen .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -27,7 +27,7 @@ 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/essentialkaos/ek.v11
go get -d -v pkg.re/essentialkaos/ek.v12
go get -d -v pkg.re/essentialkaos/go-simpleyaml.v2

fmt: ## Format source code with gofmt
Expand All @@ -44,6 +44,6 @@ help: ## Show this info
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-12s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 1.3.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 1.3.2\033[0m\n'

################################################################################
44 changes: 41 additions & 3 deletions common/yo.spec
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@

Summary: Command-line YAML processor
Name: yo
Version: 0.5.0
Version: 0.5.1
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
URL: https://github.com/essentialkaos/yo
URL: https://kaos.sh/yo

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

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

BuildRequires: golang >= 1.13
BuildRequires: golang >= 1.14

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

Expand All @@ -76,21 +76,59 @@ go build src/github.com/essentialkaos/%{name}/%{name}.go
rm -rf %{buildroot}

install -dm 755 %{buildroot}%{_bindir}
install -dm 755 %{buildroot}%{_mandir}/man1

install -pm 755 %{name} %{buildroot}%{_bindir}/

./%{name} --generate-man > %{buildroot}%{_mandir}/man1/%{name}.1

%clean
rm -rf %{buildroot}

%post
if [[ -d %{_sysconfdir}/bash_completion.d ]] ; then
%{name} --completion=bash 1> %{_sysconfdir}/bash_completion.d/%{name} 2>/dev/null
fi

if [[ -d %{_datarootdir}/fish/vendor_completions.d ]] ; then
%{name} --completion=fish 1> %{_datarootdir}/fish/vendor_completions.d/%{name}.fish 2>/dev/null
fi

if [[ -d %{_datadir}/zsh/site-functions ]] ; then
%{name} --completion=zsh 1> %{_datadir}/zsh/site-functions/_%{name} 2>/dev/null
fi

%postun
if [[ $1 == 0 ]] ; then
if [[ -f %{_sysconfdir}/bash_completion.d/%{name} ]] ; then
rm -f %{_sysconfdir}/bash_completion.d/%{name} &>/dev/null || :
fi

if [[ -f %{_datarootdir}/fish/vendor_completions.d/%{name}.fish ]] ; then
rm -f %{_datarootdir}/fish/vendor_completions.d/%{name}.fish &>/dev/null || :
fi

if [[ -f %{_datadir}/zsh/site-functions/_%{name} ]] ; then
rm -f %{_datadir}/zsh/site-functions/_%{name} &>/dev/null || :
fi
fi

################################################################################

%files
%defattr(-,root,root,-)
%doc LICENSE
%{_mandir}/man1/%{name}.1.*
%{_bindir}/%{name}

################################################################################

%changelog
* Fri Dec 04 2020 Anton Novojilov <[email protected]> - 0.5.1-0
- ek package updated to the latest stable version
- Added completion generation
- Added man page generation

* Fri Jan 10 2020 Anton Novojilov <[email protected]> - 0.5.0-0
- ek package updated to the latest stable version

Expand Down
92 changes: 76 additions & 16 deletions yo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ import (
"strconv"
"strings"

"pkg.re/essentialkaos/ek.v11/env"
"pkg.re/essentialkaos/ek.v11/fmtc"
"pkg.re/essentialkaos/ek.v11/fsutil"
"pkg.re/essentialkaos/ek.v11/options"
"pkg.re/essentialkaos/ek.v11/usage"
"pkg.re/essentialkaos/ek.v12/env"
"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/fsutil"
"pkg.re/essentialkaos/ek.v12/options"
"pkg.re/essentialkaos/ek.v12/usage"
"pkg.re/essentialkaos/ek.v12/usage/completion/bash"
"pkg.re/essentialkaos/ek.v12/usage/completion/fish"
"pkg.re/essentialkaos/ek.v12/usage/completion/zsh"
"pkg.re/essentialkaos/ek.v12/usage/man"
"pkg.re/essentialkaos/ek.v12/usage/update"

"pkg.re/essentialkaos/go-simpleyaml.v2"
)
Expand All @@ -28,7 +33,7 @@ import (

const (
APP = "Yo"
VER = "0.5.0"
VER = "0.5.1"
DESC = "Command-line YAML processor"
)

Expand All @@ -37,6 +42,9 @@ const (
OPT_NO_COLOR = "nc:no-color"
OPT_HELP = "h:help"
OPT_VER = "v:version"

OPT_COMPLETION = "completion"
OPT_GENERATE_MAN = "generate-man"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -64,6 +72,9 @@ var optMap = options.Map{
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.BOOL},

OPT_COMPLETION: {},
OPT_GENERATE_MAN: {Type: options.BOOL},
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -79,6 +90,14 @@ func main() {
os.Exit(1)
}

if options.Has(OPT_COMPLETION) {
os.Exit(genCompletion())
}

if options.Has(OPT_GENERATE_MAN) {
os.Exit(genMan())
}

configureUI()

if options.GetB(OPT_VER) {
Expand Down Expand Up @@ -538,6 +557,46 @@ func (t Token) IsArrayToken() bool {

// showUsage prints usage info
func showUsage() {
genUsage().Render()
}

// showAbout prints info about version
func showAbout() {
genAbout().Render()
}

// genCompletion generates completion for different shells
func genCompletion() int {
info := genUsage()

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "yo"))
case "fish":
fmt.Printf(fish.Generate(info, "yo"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "yo"))
default:
return 1
}

return 0
}

// genMan generates man page
func genMan() int {
fmt.Println(
man.Generate(
genUsage(),
genAbout(),
),
)

return 0
}

// genUsage generates usage info
func genUsage() *usage.Info {
info := usage.NewInfo("", "query")

info.AddOption(OPT_FROM_FILE, "Read data from file", "filename")
Expand All @@ -554,19 +613,20 @@ func showUsage() {
info.AddExample("'.xyz | keys'", "Print hash map keys")
info.AddExample("'.xyz | keys | length'", "Print number of hash map keys")

info.Render()
return info
}

// showAbout prints info about version
func showAbout() {
// genAbout generates info about version
func genAbout() *usage.About {
about := &usage.About{
App: APP,
Version: VER,
Desc: DESC,
Year: 2006,
Owner: "ESSENTIAL KAOS",
License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",
App: APP,
Version: VER,
Desc: DESC,
Year: 2006,
Owner: "ESSENTIAL KAOS",
License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",
UpdateChecker: usage.UpdateChecker{"essentialkaos/yo", update.GitHubChecker},
}

about.Render()
return about
}

0 comments on commit be8e358

Please sign in to comment.