Skip to content

Commit

Permalink
Merge pull request #51 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 3.3.0
  • Loading branch information
andyone authored Dec 5, 2023
2 parents 11c1175 + fcf2eaf commit 5bfccee
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 244 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p align="center">
<a href="https://kaos.sh/r/rep"><img src="https://kaos.sh/r/rep.svg" alt="GoReportCard" /></a>
<a href="https://kaos.sh/l/rep"><img src="https://kaos.sh/l/e3f19767174b1fd0777d.svg" alt="Code Climate Maintainability" /></a>
<a href="https://kaos.sh/l/rep"><img src="https://kaos.sh/l/5876fdc611100e9f8a83.svg" alt="Code Climate Maintainability" /></a>
<a href="https://kaos.sh/b/rep"><img src="https://kaos.sh/b/07867ea4-6025-47a8-ad18-112dd7b37a3c.svg" alt="codebeat badge" /></a>
<a href="https://kaos.sh/w/rep/ci"><img src="https://kaos.sh/w/rep/ci.svg" alt="GitHub Actions CI Status" /></a>
<a href="https://kaos.sh/w/rep/codeql"><img src="https://kaos.sh/w/rep/codeql.svg" alt="GitHub Actions CodeQL Status" /></a>
Expand Down Expand Up @@ -69,7 +69,7 @@ Commands
which-source query… Show source package name
info package Show info about package
payload package type Show package payload
cleanup num Remove old versions of packages
cleanup num filter Remove old versions of packages
check errors-num Check repositories consistency
sign file… Sign one or more packages
resign Resign all packages in repository
Expand All @@ -84,22 +84,23 @@ Commands
Options
--release, -r Run command only on release (stable) repository
--testing, -t Run command only on testing (unstable) repository
--all, -a Run command on all repositories
--arch, -aa arch Package architecture (helpful with "info" and "payload" commands)
--move, -m Move (remove after successful action) packages (helpful with "add" command)
--no-source, -ns Ignore source packages (helpful with "add" command)
--ignore-filter, -if Ignore repository file filter (helpful with "add" and "sign" commands)
--force, -f Answer "yes" for all questions
--full, -F Full reindex (helpful with "reindex" command)
--show-all, -A Show all versions of packages (helpful with "list" command)
--status, -S Show package status (released or not)
--epoch, -E Show epoch info (helpful with "list" and "which-source" commands)
--pager, -P Run command in "pager" mode (i.e. don't disable colors and don't show raw output)
--no-color, -nc Disable colors in output
--help, -h Show this help message
--version, -v Show version
--release, -r Run command only on release (stable) repository
--testing, -t Run command only on testing (unstable) repository
--all, -a Run command on all repositories
--arch, -aa arch Package architecture (helpful with "info" and "payload" commands)
--move, -m Move (remove after successful action) packages (helpful with "add" command)
--no-source, -ns Ignore source packages (helpful with "add" command)
--ignore-filter, -if Ignore repository file filter (helpful with "add" and "sign" commands)
--postpone-index, -pi Postpone repository reindex (helpful with "add", "remove", "release", and "unrelase" commands)
--force, -f Answer "yes" for all questions
--full, -F Full reindex (helpful with "reindex" command)
--show-all, -A Show all versions of packages (helpful with "list" command)
--status, -S Show package status (released or not)
--epoch, -E Show epoch info (helpful with "list" and "which-source" commands)
--pager, -P Use pager for long output
--no-color, -nc Disable colors in output
--help, -h Show this help message
--version, -v Show versio

Check warning on line 103 in README.md

View workflow job for this annotation

GitHub Actions / Typos

"versio" should be "version".

Check warning on line 103 in README.md

View workflow job for this annotation

GitHub Actions / Typos

"versio" should be "version".
```

### CI Status
Expand Down
168 changes: 80 additions & 88 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ package cli
import (
"fmt"
"os"
"strings"

"github.com/essentialkaos/ek/v12/env"
"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fmtutil"
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/knf"
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/pager"
"github.com/essentialkaos/ek/v12/progress"
"github.com/essentialkaos/ek/v12/signal"
"github.com/essentialkaos/ek/v12/system"
"github.com/essentialkaos/ek/v12/terminal"
"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 @@ -44,7 +44,7 @@ import (
// App info
const (
APP = "rep"
VER = "3.2.0"
VER = "3.3.0"
DESC = "DNF/YUM repository management utility"
)

Expand Down Expand Up @@ -144,22 +144,23 @@ const (

// Options
const (
OPT_TESTING = "t:testing"
OPT_RELEASE = "r:release"
OPT_ALL = "a:all"
OPT_ARCH = "aa:arch"
OPT_MOVE = "m:move"
OPT_NO_SOURCE = "ns:no-source"
OPT_IGNORE_FILTER = "if:ignore-filter"
OPT_FORCE = "f:force"
OPT_FULL = "F:full"
OPT_SHOW_ALL = "A:show-all"
OPT_EPOCH = "E:epoch"
OPT_STATUS = "S:status"
OPT_PAGER = "P:pager"
OPT_NO_COLOR = "nc:no-color"
OPT_HELP = "h:help"
OPT_VER = "v:version"
OPT_TESTING = "t:testing"
OPT_RELEASE = "r:release"
OPT_ALL = "a:all"
OPT_ARCH = "aa:arch"
OPT_MOVE = "m:move"
OPT_NO_SOURCE = "ns:no-source"
OPT_IGNORE_FILTER = "if:ignore-filter"
OPT_POSTPONE_INDEX = "pi:postpone-index"
OPT_FORCE = "f:force"
OPT_FULL = "F:full"
OPT_SHOW_ALL = "A:show-all"
OPT_EPOCH = "E:epoch"
OPT_STATUS = "S:status"
OPT_PAGER = "P:pager"
OPT_NO_COLOR = "nc:no-color"
OPT_HELP = "h:help"
OPT_VER = "v:version"

OPT_DEBUG = "D:debug"
OPT_VERB_VER = "vv:verbose-version"
Expand All @@ -180,22 +181,23 @@ const CONFIG_DIR = "/etc/rep.d"

// optMap is map with supported options
var optMap = options.Map{
OPT_ARCH: {},
OPT_TESTING: {Type: options.BOOL},
OPT_RELEASE: {Type: options.BOOL},
OPT_ALL: {Type: options.BOOL},
OPT_MOVE: {Type: options.BOOL},
OPT_NO_SOURCE: {Type: options.BOOL},
OPT_IGNORE_FILTER: {Type: options.BOOL},
OPT_FORCE: {Type: options.BOOL},
OPT_FULL: {Type: options.BOOL},
OPT_SHOW_ALL: {Type: options.BOOL},
OPT_EPOCH: {Type: options.BOOL},
OPT_STATUS: {Type: options.BOOL},
OPT_PAGER: {Type: options.BOOL},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},
OPT_ARCH: {},
OPT_TESTING: {Type: options.BOOL},
OPT_RELEASE: {Type: options.BOOL},
OPT_ALL: {Type: options.BOOL},
OPT_MOVE: {Type: options.BOOL},
OPT_NO_SOURCE: {Type: options.BOOL},
OPT_IGNORE_FILTER: {Type: options.BOOL},
OPT_POSTPONE_INDEX: {Type: options.BOOL},
OPT_FORCE: {Type: options.BOOL},
OPT_FULL: {Type: options.BOOL},
OPT_SHOW_ALL: {Type: options.BOOL},
OPT_EPOCH: {Type: options.BOOL},
OPT_STATUS: {Type: options.BOOL},
OPT_PAGER: {Type: options.BOOL},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

OPT_DEBUG: {Type: options.BOOL},
OPT_VERB_VER: {Type: options.BOOL},
Expand Down Expand Up @@ -274,9 +276,6 @@ func Init(gitRev string, gomod []byte) {

// configureUI configure user interface
func configureUI() {
envVars := env.Get()
term := envVars.GetS("TERM")

fmtc.DisableColors = true
fmtutil.SizeSeparator = " "
fmtutil.SeparatorSymbol = "–"
Expand All @@ -300,30 +299,23 @@ func configureUI() {
fmtc.NameColor("package", "{m}")
fmtc.NameColor("repo", "{c}")

if fmtc.IsColorsSupported() {
fmtc.DisableColors = false
}

if fmtc.Is256ColorsSupported() {
fmtc.NameColor("package", "{#108}")
fmtc.NameColor("repo", "{#33}")
progress.DefaultSettings.BarFgColorTag = "{#33}"
}

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

if options.GetB(OPT_NO_COLOR) {
fmtc.DisableColors = true
}

if !options.GetB(OPT_PAGER) {
if !fsutil.IsCharacterDevice("/dev/stdout") && envVars.GetS("FAKETTY") == "" {
fmtc.DisableColors = true
rawOutput = true
}
if !tty.IsTTY() {
fmtc.DisableColors = true
rawOutput = true
}
}

Expand All @@ -333,12 +325,12 @@ func checkPermissions() {

if err != nil {
terminal.Error("Can't get info about current user: %v", err)
os.Exit(1)
shutdown(1)
}

if !curUser.IsRoot() {
terminal.Error("This app requires superuser (root) privileges")
os.Exit(1)
shutdown(1)
}
}

Expand All @@ -348,7 +340,7 @@ func loadGlobalConfig() {

if err != nil {
terminal.Error(err.Error())
os.Exit(1)
shutdown(1)
}
}

Expand Down Expand Up @@ -383,7 +375,7 @@ func validateGlobalConfig() {
terminal.Error(" - %v", err)
}

os.Exit(1)
shutdown(1)
}

// loadRepoConfigs loads repositories configuration files
Expand All @@ -404,7 +396,7 @@ func loadRepoConfigs() {

if err != nil {
terminal.Error(err.Error())
os.Exit(1)
shutdown(1)
}

configs[cfg.GetS(REPOSITORY_NAME)] = cfg
Expand Down Expand Up @@ -448,7 +440,7 @@ func validateRepoConfigs() {
}

if hasErrors {
os.Exit(1)
shutdown(1)
}
}

Expand All @@ -472,7 +464,7 @@ func configureRepoCache() {
}

if hasErrors {
os.Exit(1)
shutdown(1)
}
}

Expand Down Expand Up @@ -521,6 +513,12 @@ func process(args options.Arguments) bool {
return false
}

if options.GetB(OPT_PAGER) && tty.IsTTY() {
if pager.Setup() == nil {
defer pager.Complete()
}
}

// List repositories by default
if args.Get(1).String() == "" {
return runCommand(configs[repo], COMMAND_LIST, nil)
Expand Down Expand Up @@ -551,11 +549,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, APP))
fmt.Print(bash.Generate(info, APP))
case "fish":
fmt.Printf(fish.Generate(info, APP))
fmt.Print(fish.Generate(info, APP))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, APP))
fmt.Print(zsh.Generate(info, optMap, APP))
default:
return 1
}
Expand All @@ -573,27 +571,18 @@ func printMan() {
)
}

// 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()

if fmtc.Is256ColorsSupported() {
info.AppNameColorTag = "{*}{#33}"
}

info.AddSpoiler(
"Notice that if you have more than one repository you should define its name as\n" +
"the first argument. You can read detailed info about every command with usage\n" +
"examples using {y}help{!} command.",
)
` Note that if you have more than one repository, you should specify its name
as the first argument. You can read detailed information about each command
with usage examples by using the {y}help{!} command.`)

info.AddCommand(COMMAND_INIT, "Initialize new repository", "arch…")
info.AddCommand(COMMAND_GEN_KEY, "Generate keys for signing packages")
Expand All @@ -602,7 +591,7 @@ func genUsage() *usage.Info {
info.AddCommand(COMMAND_WHICH_SOURCE, "Show source package name", "query…")
info.AddCommand(COMMAND_INFO, "Show info about package", "package")
info.AddCommand(COMMAND_PAYLOAD, "Show package payload", "package", "?type")
info.AddCommand(COMMAND_CLEANUP, "Remove old versions of packages", "?num")
info.AddCommand(COMMAND_CLEANUP, "Remove old versions of packages", "?num", "?filter")
info.AddCommand(COMMAND_CHECK, "Check repositories consistency", "?errors-num")
info.AddCommand(COMMAND_SIGN, "Sign one or more packages", "file…")
info.AddCommand(COMMAND_RESIGN, "Resign all packages in repository")
Expand All @@ -618,16 +607,17 @@ func genUsage() *usage.Info {
info.AddOption(OPT_RELEASE, "Run command only on release {s}(stable){!} repository")
info.AddOption(OPT_TESTING, "Run command only on testing {s}(unstable){!} repository")
info.AddOption(OPT_ALL, "Run command on all repositories")
info.AddOption(OPT_ARCH, "Package architecture {s-}(helpful with \"info\" and \"payload\" commands){!}", "arch")
info.AddOption(OPT_MOVE, "Move {s}(remove after successful action){!} packages {s-}(helpful with \"add\" command){!}")
info.AddOption(OPT_NO_SOURCE, "Ignore source packages {s-}(helpful with \"add\" command){!}")
info.AddOption(OPT_IGNORE_FILTER, "Ignore repository file filter {s-}(helpful with \"add\" and \"sign\" commands){!}")
info.AddOption(OPT_FORCE, "Answer \"yes\" for all questions")
info.AddOption(OPT_FULL, "Full reindex {s-}(helpful with \"reindex\" command){!}")
info.AddOption(OPT_SHOW_ALL, "Show all versions of packages {s-}(helpful with \"list\" command){!}")
info.AddOption(OPT_ARCH, `Package architecture {s-}(helpful with "info" and "payload" commands){!}`, "arch")
info.AddOption(OPT_MOVE, `Move {s}(remove after successful action){!} packages {s-}(helpful with "add" command){!}`)
info.AddOption(OPT_NO_SOURCE, `Ignore source packages {s-}(helpful with "add" command){!}`)
info.AddOption(OPT_IGNORE_FILTER, `Ignore repository file filter {s-}(helpful with "add" and "sign" commands){!}`)
info.AddOption(OPT_POSTPONE_INDEX, `Postpone repository reindex {s-}(helpful with "add", "remove", "release", and "unrelase" commands){!}`)
info.AddOption(OPT_FORCE, `Answer "yes" for all questions`)
info.AddOption(OPT_FULL, `Full reindex {s-}(helpful with "reindex" command){!}`)
info.AddOption(OPT_SHOW_ALL, `Show all versions of packages {s-}(helpful with "list" command){!}`)
info.AddOption(OPT_STATUS, "Show package status {s-}(released or not){!}")
info.AddOption(OPT_EPOCH, "Show epoch info {s-}(helpful with \"list\" and \"which-source\" commands){!}")
info.AddOption(OPT_PAGER, "Run command in \"pager\" mode {s-}(i.e. don't disable colors and don't show raw output){!}")
info.AddOption(OPT_EPOCH, `Show epoch info {s-}(helpful with "list" and "which-source" commands){!}`)
info.AddOption(OPT_PAGER, "Use pager for long output")
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
info.AddOption(OPT_HELP, "Show this help message")
info.AddOption(OPT_VER, "Show version")
Expand Down Expand Up @@ -685,6 +675,8 @@ func genAbout(gitRev string) *usage.About {
Owner: "ESSENTIAL KAOS",
License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",
UpdateChecker: usage.UpdateChecker{"essentialkaos/rep", update.GitHubChecker},

DescSeparator: "{s}—{!}",
}

if gitRev != "" {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func addRPMFiles(ctx *context, files []string, signingKey *sign.Key) bool {
hasAdded = true
}

if hasAdded {
if hasAdded && !options.GetB(OPT_POSTPONE_INDEX) {
fmtc.NewLine()
reindexRepository(ctx, ctx.Repo.Testing, false)
}
Expand Down
Loading

0 comments on commit 5bfccee

Please sign in to comment.