Skip to content

Commit

Permalink
Merge pull request #107 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.1.1
  • Loading branch information
andyone authored Jun 22, 2024
2 parents 7f2220b + 39b7644 commit 305fe5c
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 104 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ updates:
- "andyone"
reviewers:
- "andyone"
groups:
all:
applies-to: version-updates
update-types:
- "minor"
- "patch"

- package-ecosystem: "github-actions"
directory: "/"
Expand Down
5 changes: 5 additions & 0 deletions .github/images/card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .github/images/license.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions .github/images/usage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 39 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
################################################################################

# This Makefile generated by GoMakeGen 2.3.0 using next command:
# This Makefile generated by GoMakeGen 3.0.2 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen

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

export GO111MODULE=on

ifdef VERBOSE ## Print verbose information (Flag)
VERBOSE_FLAG = -v
endif

COMPAT ?= 1.18
COMPAT ?= 1.19
MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)

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

.DEFAULT_GOAL := help
.PHONY = fmt vet all clean deps update init vendor mod-init mod-update mod-download mod-vendor help
.PHONY = fmt vet all install uninstall clean deps update init vendor mod-init mod-update mod-download mod-vendor help

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

all: icecli ## Build all binaries

icecli:
go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" icecli.go
@echo "Building icecli…"
@go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" icecli.go

install: ## Install all binaries
cp icecli /usr/bin/icecli
@echo "Installing binaries…"
@cp icecli /usr/bin/icecli

uninstall: ## Uninstall all binaries
rm -f /usr/bin/icecli
@echo "Removing installed binaries…"
@rm -f /usr/bin/icecli

init: mod-init ## Initialize new module

Expand All @@ -44,57 +45,70 @@ update: mod-update ## Update dependencies to the latest versions
vendor: mod-vendor ## Make vendored copy of dependencies

mod-init:
@echo "[1/2] Modules initialization…"
ifdef MODULE_PATH ## Module path for initialization (String)
go mod init $(MODULE_PATH)
@go mod init $(MODULE_PATH)
else
go mod init
@go mod init
endif

@echo "[2/2] Dependencies cleanup…"
ifdef COMPAT ## Compatible Go version (String)
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
@go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
else
go mod tidy $(VERBOSE_FLAG)
@go mod tidy $(VERBOSE_FLAG)
endif

mod-update:
@echo "[1/4] Updating dependencies…"
ifdef UPDATE_ALL ## Update all dependencies (Flag)
go get -u $(VERBOSE_FLAG) all
@go get -u $(VERBOSE_FLAG) all
else
go get -u $(VERBOSE_FLAG) ./...
@go get -u $(VERBOSE_FLAG) ./...
endif

@echo "[2/4] Stripping toolchain info…"
@grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || :

@echo "[3/4] Dependencies cleanup…"
ifdef COMPAT
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
@go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
else
go mod tidy $(VERBOSE_FLAG)
@go mod tidy $(VERBOSE_FLAG)
endif

test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :
@echo "[4/4] Updating vendored dependencies…"
@test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

mod-download:
go mod download
@echo "Downloading dependencies…"
@go mod download

mod-vendor:
rm -rf vendor && go mod vendor $(VERBOSE_FLAG)
@echo "Vendoring dependencies…"
@rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

fmt: ## Format source code with gofmt
find . -name "*.go" -exec gofmt -s -w {} \;
@echo "Formatting sources…"
@find . -name "*.go" -exec gofmt -s -w {} \;

vet: ## Runs 'go vet' over sources
go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./...
@echo "Running 'go vet' over sources…"
@go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./...

clean: ## Remove generated files
rm -f icecli
@echo "Removing built binaries…"
@rm -f icecli

help: ## Show this info
@echo -e '\n\033[1mTargets:\033[0m\n'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-14s\033[0m %s\n", $$1, $$2}'
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-9s\033[0m %s\n", $$1, $$2}'
@echo -e '\n\033[1mVariables:\033[0m\n'
@grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.3.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 3.0.2\033[0m\n'

################################################################################
46 changes: 6 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<p align="center"><a href="#readme"><img src="https://gh.kaos.st/icecli.svg"/></a></p>
<p align="center"><a href="#readme"><img src=".github/images/card.svg"/></a></p>

<p align="center">
<a href="https://kaos.sh/w/icecli/ci"><img src="https://kaos.sh/w/icecli/ci.svg" alt="GitHub Actions CI Status" /></a>
<a href="https://kaos.sh/w/icecli/codeql"><img src="https://kaos.sh/w/icecli/codeql.svg" alt="GitHub Actions CodeQL Status" /></a>
<a href="https://kaos.sh/b/icecli"><img src="https://kaos.sh/b/455126f6-4d86-4c9f-af47-6a4c180bb5e7.svg" alt="Codebeat badge" /></a>
<a href="https://kaos.sh/r/icecli"><img src="https://kaos.sh/r/icecli.svg" alt="GoReportCard" /></a>
<a href="#license"><img src="https://gh.kaos.st/apache2.svg"></a>
<a href="#license"><img src=".github/images/license.svg"/></a>
</p>

<p align="center"><a href="#installation">Installation</a> • <a href="#command-line-completion">Command-line completion</a> • <a href="#usage">Usage</a> • <a href="#build-status">Build Status</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a></p>
<p align="center"><a href="#installation">Installation</a> • <a href="#command-line-completion">Command-line completion</a> • <a href="#usage">Usage</a> • <a href="#ci-status">CI Status</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a></p>

</br>

Expand All @@ -18,7 +18,7 @@

#### From source

To build the `icecli` from scratch, make sure you have a working Go 1.18+ workspace (_[instructions](https://go.dev/doc/install)_), then:
To build the `icecli` from scratch, make sure you have a working Go 1.21+ workspace (_[instructions](https://go.dev/doc/install)_), then:

```bash
go install github.com/essentialkaos/icecli@latest
Expand Down Expand Up @@ -55,43 +55,9 @@ sudo icecli --completion=fish 1> /usr/share/fish/vendor_completions.d/icecli.fis

### Usage

```
Usage: icecli {options} {command} arguments…
Commands
stats Show Icecast statistics
list-mounts List mount points
list-clients mount List clients
move-clients from-mount to-mount Move clients between mounts
update-meta mount artist title Update meta for mount
kill-client mount client-id Kill client connection
kill-source mount Kill source connection
help command Show detailed info about command usage
Options
--host, -H host URL of Icecast instance (default: http://127.0.0.1:8000)
--user, -U username Admin username (default: admin)
--password, -P password Admin password (default: hackme)
--no-color, -nc Disable colors in output
--help, -h Show this help message
--version, -v Show version
Examples
icecli stats -H 127.0.0.1:10000
Show stats for server on 127.0.0.1:10000
icecli kill-client -P mYsUpPaPaSs /stream3 361
Detach client with ID 361 from /stream3
icecli list-clients -H 127.0.0.1:10000 -U super_admin -P mYsUpPaPaSs /stream3
List clients on /stream3
```
<p align="center"><img src=".github/images/usage.svg"/></p>

### Build Status
### CI Status

| Branch | Status |
|--------|--------|
Expand Down
29 changes: 8 additions & 21 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/essentialkaos/ek/v12/support"
"github.com/essentialkaos/ek/v12/support/deps"
"github.com/essentialkaos/ek/v12/support/pkgs"
"github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/timeutil"
"github.com/essentialkaos/ek/v12/usage"
Expand All @@ -38,7 +39,7 @@ import (
const (
APP = "icecli"
DESC = "Icecast CLI"
VER = "1.1.0"
VER = "1.1.1"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -100,13 +101,9 @@ func Run(gitRev string, gomod []byte) {

args, errs := options.Parse(optMap)

if len(errs) != 0 {
printError("Options parsing errors:")

for _, err := range errs {
printError(" %v", err)
}

if !errs.IsEmpty() {
terminal.Error("Options parsing errors:")
terminal.Error(errs.String())
os.Exit(1)
}

Expand Down Expand Up @@ -215,7 +212,7 @@ func execCommand(args options.Arguments) {
checkForRequiredArgs(args, 1)
killSource(args.Get(1).String())
default:
printError("Unknown or unsupported command %q", cmd)
terminal.Error("Unknown or unsupported command %q", cmd)
os.Exit(1)
}
}
Expand Down Expand Up @@ -524,14 +521,9 @@ func checkForRequiredArgs(args options.Arguments, required int) {
)
}

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

// printErrorExit prints error message to console and exit with error code
func printErrorExit(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...)
terminal.Error(f, a...)
os.Exit(1)
}

Expand Down Expand Up @@ -676,12 +668,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
Loading

0 comments on commit 305fe5c

Please sign in to comment.