Compare commits

..

20 Commits

Author SHA1 Message Date
66a7f794e0 Change import path to go.arsenm.dev/pak 2021-06-28 18:01:37 -07:00
407d4b06cd Remove .acorn directory 2021-05-23 03:41:56 -07:00
cdece4f0ad Remove extraneous error file and add go.sum 2021-05-23 03:37:35 -07:00
8269c4bcc1 Add AdvMakefile and .gitm.toml 2021-05-22 17:26:48 -07:00
47eeacf1a5 Add AdvMakefile and .gitm.toml 2021-05-22 17:25:36 -07:00
a35f05a13e Clean up code 2021-05-06 10:50:27 -07:00
8480882b32 Only sanitize user input 2021-05-05 14:06:18 -07:00
663a4e8920 Sanitize shell input 2021-05-05 14:00:44 -07:00
98dcb1532e Implement running non-manager commands in config 2021-01-09 01:14:40 -08:00
661242582e Clean up code and switch to zerolog [skip ci] 2021-01-04 02:33:29 -08:00
51071dc4cf Simplify makefile [skip ci] 2021-01-03 23:49:32 -08:00
93c80f01b8 Revamp config, Gofmt project, and clean up unneeded code 2021-01-03 19:41:26 -08:00
a7428315e3 Fix flag removal regex 2020-11-30 15:40:40 -08:00
0bffa3e2a4 Switch to TOML config [skip ci] 2020-11-30 15:27:29 -08:00
e4dcb180be Use golang flag package [skip ci] 2020-11-30 14:25:31 -08:00
34208e4399 Prioritize shortcuts over commands [skip ci] 2020-11-28 16:38:45 -08:00
fb89448324 Show shortcut mappings in help screen [skip ci] 2020-11-27 19:06:05 -08:00
dbd6a3162d Add override for package manager 2020-11-27 18:26:42 -08:00
33a2a834ab Fix makefile [skip ci] 2020-11-25 20:41:17 -08:00
0d87a65575 Fix makefile [skip ci] 2020-11-25 20:40:59 -08:00
24 changed files with 478 additions and 280 deletions

View File

@@ -1 +0,0 @@
make

View File

@@ -1,13 +0,0 @@
if command -v apt &> /dev/null; then
make aptinstall
elif command -v aptitude &> /dev/null; then
make aptitude
elif command -v brew &> /dev/null; then
make brewinstall
elif command -v zypper &> /dev/null; then
make zyppinstall
elif command -v yay &> /dev/null; then
make yayinstall
elif command -v pacman &> /dev/null; then
make pacinstall
fi

View File

@@ -1,16 +0,0 @@
name = "Pak"
desc = "Wrapper written in Go designed for package managers to unify software management commands between distros"
[dependencies]
brew = []
apt = []
dnf = []
yum = []
zypper = []
yay = []
pacman = []
[scripts]
build = "build.sh"
install = "install.sh"
remove = "remove.sh"

View File

@@ -1,2 +0,0 @@
rm /usr/bin/pak
rm /etc/pak.cfg

1
.gitignore vendored
View File

@@ -2,4 +2,5 @@ pak
pak-linux-x86_64
pak-linux-aarch64
pak-macos
pak-new.toml
.idea

4
.gitm.toml Normal file
View File

@@ -0,0 +1,4 @@
[repos]
origin = "ssh://git@192.168.100.62:2222/Arsen6331/pak.git"
gitlab = "git@gitlab.com:moussaelianarsen/pak.git"
github = "git@github.com:Arsen6331/pak.git"

39
AdvMakefile Normal file
View File

@@ -0,0 +1,39 @@
defaultName = "pak"
defaultTarget = "build"
availableManagers = [
"apk",
"apt",
"aptitude",
"brew",
"dnf",
"yum",
"npm",
"pacman",
"yay",
"pip",
"snap",
"zypper"
]
def pak_build():
if lookPath("go") == -1:
log("Go must be installed to compile pak", level="fatal")
execute("go build")
def pak_install():
mappings = {"PKGMANAGER": userChoice("Choose package manager", availableManagers)}
expandFile("pak.toml", mappings)
execute("""
install -Dm755 pak $DESTDIR/usr/bin/pak
install -Dm644 pak.toml $DESTDIR/etc/pak.toml
""")
def pak_install_noninteractive():
expandFile("pak.toml", {"PKGMANAGER": getEnv("PAK_CFG_MGR")})
execute("""
install -Dm755 pak $DESTDIR/usr/bin/pak
install -Dm644 pak.toml $DESTDIR/etc/pak.toml
""")

View File

@@ -1,38 +1,15 @@
GOBUILD ?= go build
pak: pak.go
$(GOBUILD) pak.go
all: main.go
$(GOBUILD)
install: PAK_CFG_MGR ?= apt
install: pak.toml pak
install -Dm755 pak $(DESTDIR)/usr/bin/pak
sed -i 's/activeManager = "\$PKGMANAGER"/activeManager = "$(PAK_CFG_MGR)"/' pak.toml
install -Dm644 pak.toml $(DESTDIR)/etc/pak.toml
installbinonly: pak
install -Dm755 pak $(DESTDIR)/usr/bin/pak
aptinstall: pak.cfg pak
install -Dm644 pak.cfg $(DESTDIR)/etc/pak.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak
snapinstall: plugins/snap/pak.cfg pak
install -Dm644 plugins/snap/pak.cfg $(DESTDIR)/etc/pak.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak
yayinstall: plugins/yay/pak.cfg pak
install -Dm644 plugins/yay/pak.cfg $(DESTDIR)/etc/pak.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak
pacinstall: plugins/pacman/pak.cfg pak
install -Dm644 plugins/pacman/pak.cfg $(DESTDIR)/etc/pak.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak
aptitude: plugins/aptitude/pak.cfg pak
install -Dm644 plugins/aptitude/pak.cfg $(DESTDIR)/etc/pak.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak
brewinstall: plugins/brew/pak.cfg pak
mount -uw /
install -m644 plugins/brew/pak.cfg $(DESTDIR)/etc/pak.cfg
install -m755 pak $(DESTDIR)/usr/bin/pak
zyppinstall: plugins/zypper/pak.cfg pak
install -Dm644 plugins/zypper/pak.cfg $(DESTDIR)/etc/pak.cfg
install -Dm755 pak $(DESTDIR)/usr/bin/pak
.PHONY: pak $(MAKECMDGOALS)
.PHONY: all install installbinonly

39
config.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import (
"github.com/pelletier/go-toml"
"io/ioutil"
"path/filepath"
)
// Config contains the root of the TOML config file
type Config struct {
ActiveManager string
RootCommand string
Managers map[string]Manager
}
// Manager contains the root of all manager sections in the TOML config file
type Manager struct {
UseRoot bool
Commands map[string]string
Shortcuts map[string]string
}
// Create new Config{} with values from file path given
func NewConfig(path string) Config {
// Read file at path
data, err := ioutil.ReadFile(path)
if err != nil {
Log.Fatal().Err(err).Str("file", filepath.Base(path)).Msg("Error reading config")
}
// Create new Config{}
cfg := Config{}
// Unmarshal TOML in config
err = toml.Unmarshal(data, &cfg)
if err != nil {
Log.Fatal().Err(err).Str("file", filepath.Base(path)).Msg("Error unmarshalling TOML")
}
// Return config
return cfg
}

View File

@@ -41,7 +41,6 @@ func Jaro(a, b string) float64 {
return ((matches / la) + (matches / lb) + (matches-transposes)/matches) / 3.0
}
func JaroWinkler(a, b string, boostThreshold float64, prefixSize int) float64 {
j := Jaro(a, b)

55
extra.go Normal file
View File

@@ -0,0 +1,55 @@
package main
// Check if slice contains string
func Contains(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}
func Max(array []float64) float64 {
var max = array[0]
var min = array[0]
for _, value := range array {
if max < value {
max = value
}
if min > value {
min = value
}
}
return max
}
// Get key from map given value
func GetKey(inMap map[string]string, val string) string {
// For every key/value pair in map
for key, value := range inMap {
// If value found
if value == val {
// Return key
return key
}
}
// If fails, return empty string
return ""
}
// Get slice of float64 given map[string]float64
func GetValuesDist(inMap map[string]float64) []float64 {
// Make new slice with set capacity
values := make([]float64, len(inMap))
// Set index to 0
index := 0
for _, value := range inMap {
// Set index of slice to value
values[index] = value
// Increment index
index++
}
// Return completed slice
return values
}

10
go.mod Normal file
View File

@@ -0,0 +1,10 @@
module go.arsenm.dev/pak
go 1.15
require (
github.com/alessio/shellescape v1.4.1
github.com/pelletier/go-toml v1.8.2-0.20201124181426-2e01f733df54
github.com/rs/zerolog v1.20.0
github.com/spf13/pflag v1.0.5
)

30
go.sum Normal file
View File

@@ -0,0 +1,30 @@
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pelletier/go-toml v1.8.2-0.20201124181426-2e01f733df54 h1:U7n5zyrdmyUTvXR7DRuSRrdFBkjcIPeCjSG2GScQSL8=
github.com/pelletier/go-toml v1.8.2-0.20201124181426-2e01f733df54/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs=
github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74 h1:4cFkmztxtMslUX2SctSl+blCyXfpzhGOy9LhKAqSMA4=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

162
main.go
View File

@@ -20,128 +20,137 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"github.com/alessio/shellescape"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
flag "github.com/spf13/pflag"
"os"
"os/exec"
"os/user"
"regexp"
"strings"
)
var Log = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
func main() {
// Put all arguments into a variable
args := os.Args[1:]
// Check which currentUser is running command
// Create help flag
helpFlagGiven := flag.BoolP("help", "h", false, "Show help screen")
// Create package manager override flag
packageManagerOverride := flag.StringP("package-manager", "p", os.Getenv("PAK_MGR_OVERRIDE"), "Override package manager wrapped by pak")
// Parse arguments for flags
flag.Parse()
// Check which user is running command
currentUser, err := user.Current()
if err != nil { log.Fatal(err) }
// Check to make sure root is not being used unless -r/--root specified
if !Contains(args, "-r") && !Contains(args, "--root") {
if err != nil {
Log.Fatal().Err(err).Msg("Error getting current user")
}
// If running as root
if strings.Contains(currentUser.Username, "root") {
fmt.Println("Do not run as root, this program will invoke root for you if selected in config.")
fmt.Println("If you would like to bypass this, run this command with -r or --root.")
os.Exit(1)
// Print warning message
Log.Warn().Msg("Running as root may cause extraneous root invocation")
}
// Get arguments without flags
args := flag.Args()
// Define variables for config file location, and override state boolean
var isOverridden bool
// Read /etc/pak.toml into new Config{}
config := NewConfig("/etc/pak.toml")
// If override is set
if *packageManagerOverride != "" {
// Set active package manager to override
config.ActiveManager = *packageManagerOverride
// Set override state to true
isOverridden = true
} else {
if Contains(args, "-r") {
args = removeAtIndex(args, Find(args, "-r"))
} else if Contains(args, "--root") {
args = removeAtIndex(args, Find(args, "--root"))
// Set override state to false
isOverridden = false
}
}
// Parse config file removing all comments and empty lines
config, err := ioutil.ReadFile("/etc/pak.cfg")
if err != nil { log.Fatal(err) }
commentRegex := regexp.MustCompile(`#.*`)
emptyLineRegex := regexp.MustCompile(`(?m)^\s*\n`)
parsedConfig := commentRegex.ReplaceAllString(string(config), "")
parsedConfig = emptyLineRegex.ReplaceAllString(parsedConfig, "")
cfg := strings.Split(parsedConfig, "\n")
//fmt.Println(cfg) //DEBUG
// Set first line of config to variable
packageManagerCommand := cfg[0]
//fmt.Println(packageManagerCommand) //DEBUG
// Parse list of commands in config line 2 and set to variable as array
commands := strings.Split(cfg[1], ",")
commands := config.Managers[config.ActiveManager].Commands
//fmt.Println(commands) //DEBUG
// Set the root option in config line 3 to a variable
useRoot := cfg[2]
useRoot := config.Managers[config.ActiveManager].UseRoot
//fmt.Println(useRoot) //DEBUG
// Set command to use to invoke root at config line 4 to a variable
rootCommand := cfg[3]
rootCommand := config.RootCommand
//fmt.Println(rootCommand) //DEBUG
// Parse list of shortcuts in config and line 5 set to variable as an array
shortcuts := strings.Split(cfg[4], ",")
shortcuts := config.Managers[config.ActiveManager].Shortcuts
//fmt.Println(shortcuts) //DEBUG
// Parse list of shortcuts in config line 6 and set to variable as array
shortcutMappings := strings.Split(cfg[5], ",")
//fmt.Println(shortcutMappings) //DEBUG
// Check if config file allows root and set boolean to a variable
var useRootBool bool
if useRoot == "yes" {
useRootBool = true
} else if useRoot == "no" {
useRootBool = false
}
//fmt.Println(useRootBool) //DEBUG
// Create similar to slice to put all matched commands into
var similarTo []string
similarTo := []string{}
// Displays help message if no arguments provided or -h/--help is passed
if len(args) == 0 || Contains(args, "-h") || Contains(args, "--help") || Contains(args, "help") {
printHelpMessage(packageManagerCommand, useRootBool, rootCommand, commands, shortcuts)
if len(args) == 0 || *helpFlagGiven || Contains(args, "help") {
printHelpMessage(config.ActiveManager, rootCommand, commands, shortcuts, useRoot, isOverridden)
os.Exit(0)
}
// Create distance slice to store JaroWinkler distance values
var distance []float64
distance := map[string]float64{}
// Appends JaroWinkler distance between each available command and the first argument to an array
for _,command := range commands {
distance = append(distance, JaroWinkler(command, args[0], 1, 0))
}
// Compares each distance to the max of the distance slice and appends the closest command to similarTo
for index, element := range distance {
// If current element is the closest to the first argument
if element == Max(distance) {
// Append command at same index as distance to similarTo
similarTo = append(similarTo, commands[index])
}
for command := range commands {
distance[command] = JaroWinkler(command, args[0], 1, 0)
}
// Deals with shortcuts
for index, shortcut := range shortcuts {
for shortcut, mapping := range shortcuts {
// If the first argument is a shortcut and similarTo does not already contain its mapping, append it
if args[0] == shortcut && !Contains(similarTo, shortcutMappings[index]) {
similarTo = append(similarTo, shortcutMappings[index])
if args[0] == shortcut && !Contains(similarTo, mapping) {
similarTo = append(similarTo, mapping)
}
}
// Compares each distance to the max of the distance slice and appends the closest command to similarTo
for command, cmdDist := range distance {
// If current element is the closest to the first argument
if cmdDist == Max(GetValuesDist(distance)) {
// Append command at same index as distance to similarTo
similarTo = append(similarTo, commands[command])
}
}
// If similarTo is still empty, log it fatally as something is wrong with the config or the code
if len(similarTo) == 0 { log.Fatalln("This command does not match any known commands or shortcuts") }
if len(similarTo) == 0 {
Log.Fatal().Msg("This command does not match any known commands or shortcuts")
}
var overriddenStr string
if isOverridden {
overriddenStr = "(overridden)"
} else {
overriddenStr = ""
}
// Print text showing command being run and package manager being used
fmt.Println("Running:", strings.Title(similarTo[0]), "using", strings.Title(packageManagerCommand))
fmt.Println("Running:", strings.Title(GetKey(commands, similarTo[0])), "using", strings.Title(config.ActiveManager), overriddenStr)
// Run package manager with the proper arguments passed if more than one argument exists
var cmdArr []string
// If root is to be used, append it to cmdArr
if useRootBool { cmdArr = append(cmdArr, rootCommand) }
// Create slice with all commands and arguments for the package manager
cmdArr = append(cmdArr, []string{packageManagerCommand, similarTo[0]}...)
if useRoot {
cmdArr = append(cmdArr, rootCommand)
}
// If command to be run has a prefix of "cmd:"
if strings.HasPrefix(similarTo[0], "cmd:") {
// Append the command to the slice without the prefix
cmdArr = append(cmdArr, strings.TrimPrefix(similarTo[0], "cmd:"))
} else {
// Otherwise, append all commands and arguments for the package manager to slice
cmdArr = append(cmdArr, config.ActiveManager, similarTo[0])
}
// If greater than 2 arguments, append them to cmdArr
if len(args) >= 2 { cmdArr = append(cmdArr, strings.Join(args[1:], " ")) }
if len(args) >= 2 {
cmdArr = append(cmdArr, shellescape.QuoteCommand(args[1:]))
}
// Create space separated string from cmdArr
cmdStr := strings.Join(cmdArr, " ")
// Instantiate exec.Command object with command sh, flag -c, and cmdStr
@@ -154,7 +163,6 @@ func main() {
err = command.Run()
// If command returned an error, log fatally with explanation
if err != nil {
fmt.Println("Error received from child process")
log.Fatal(err)
Log.Fatal().Err(err).Msg("Error received from child process")
}
}

13
pak.cfg
View File

@@ -1,13 +0,0 @@
# Write the name of the package manager in all lowercase below
apt
# Write a comma separated list of commands from the manager below
install,remove,update,upgrade,search,download
# Write "yes" or "no" depending on whether you want to use sudo
yes
# Write command to use for root
sudo
# Write a comma separated list of shortcuts below
rm,inst
# Write a comma separated list of shortcut mappings from the manager below
remove,install

184
pak.toml Normal file
View File

@@ -0,0 +1,184 @@
activeManager = "$PKGMANAGER"
rootCommand = "sudo"
[managers]
[managers.apt]
useRoot = true
[managers.apt.commands]
install = "install"
remove = "remove"
search = "search"
list = "list"
refresh = "update"
upgrade = "upgrade"
download = "download"
clean = "clean"
file-refresh = "cmd:apt-file update"
file-search = "cmd:apt-file search"
add-key = "cmd:apt-key add"
add-repo = "cmd:add-apt-repository"
[managers.apt.shortcuts]
arm = "autoremove"
[managers.aptitude]
useRoot = true
[managers.aptitude.commands]
install = "install"
remove = "remove"
download = "download"
refresh = "update"
upgrade = "upgrade"
full-upgrade = "full-upgrade"
safe-upgrade = "safe-upgrade"
clean = "clean"
hold = "hold"
unhold = "unhold"
mark-auto = "markauto"
unmark-auto = "unmarkauto"
why = "why"
whynot = "whynot"
reinstall = "reinstall"
search = "search"
show = "show"
list = "search '~i'"
changelog = "changelog"
file-refresh = "cmd:apt-file update"
file-search = "cmd:apt-file search"
add-key = "cmd:apt-key add"
add-repo = "cmd:add-apt-repository"
[managers.brew]
useRoot = false
[managers.brew.commands]
install = "install"
remove = "remove"
reinstall = "reinstall"
cask-install = "cask install"
cask-remove = "cask remove"
cask-reinstall = "cask reinstall"
cask = "cask"
list = "list"
refresh = "update"
upgrade = "upgrade"
search = "search"
doctor = "doctor"
edit = "edit"
[managers.snap]
useRoot = true
[managers.snap.commands]
install = "install"
remove = "remove"
upgrade = "refresh"
downgrade = "revert"
run = "run"
download = "download"
[managers.npm]
useRoot = false
[managers.npm.commands]
whoami = "whoami"
view = "view"
version = "version"
update = "update"
test = "test"
stop = "stop"
start = "start"
publish = "publish"
prune = "prune"
deprecate = "deprecate"
doctor = "doctor"
logout = "logout"
login = "login"
list = "list"
link = "link"
rebuild = "rebuild"
repo = "repo"
search = "search"
docs = "docs"
create = "create"
remove = "uninstall"
install = "install"
[managers.pip]
useRoot = false
[managers.pacman]
useRoot = true
[managers.pacman.commands]
install = "-S"
remove = "-R"
upgrade = "-Syu"
update = "-Su"
refresh = "-Sy"
autoremove = "-Rss $(pacman -Qdtq)"
search = "-Ss"
list = "-Qi"
file-refresh = "-Fy"
file-search = "-Fx"
[managers.pacman.shortcuts]
arm = "-Rss $(pacman -Qdtq)"
[managers.yay]
useRoot = false
[managers.yay.commands]
install = "-S"
remove = "-R"
upgrade = "-Syu"
update = "-Su"
refresh = "-Sy"
autoremove = "-Rss $(yay -Qdtq)"
search = "-Ss"
list = "-Qi"
file-refresh = "-Fy"
file-search = "-Fx"
interactive = ""
[managers.yay.shortcuts]
arm = "-Rss $(yay -Qdtq)"
[managers.apk]
useRoot = true
[managers.apk.commands]
install = "add"
remove = "del"
fix = "fix"
refresh = "update"
upgrade = "upgrade"
search = "search"
list = "info"
[managers.dnf]
useRoot = true
[managers.dnf.commands]
install = "install"
remove = "remove"
reinstall = "reinstall"
list = "list"
search = "search"
clean = "clean"
downgrade = "downgrade"
[managers.yum]
useRoot = true
[managers.yum.commands]
install = "install"
remove = "remove"
reinstall = "reinstall"
list = "list"
search = "search"
clean = "clean"
downgrade = "downgrade"
[managers.zypper]
useRoot = true
[managers.zypper.commands]
install = "install"
remove = "remove"
refresh = "refresh"
clean = "clean"
addrepo = "addrepo"
removerepo = "removerepo"
list-repos = "repos"
list = "packages -i"
search = "search"

View File

@@ -1,13 +0,0 @@
# Write the name of the package manager in all lowercase below
aptitude
# Write a comma separated list of commands from the manager below
install,remove,download,update,upgrade,full-upgrade,safe-upgrade,clean,hold,unhold,markauto,unmarkauto,why,whynot,reinstall,search,show,changelog
# Write "yes" or "no" depending on whether you want to use sudo
yes
# Write command to use for root
sudo
# Write a comma separated list of shortcuts below
rm,inst
# Write a comma separated list of shortcut mappings from the manager below
remove,install

View File

@@ -1,13 +0,0 @@
# Write the name of the package manager in all lowercase below
brew
# Write a comma separated list of commands from the manager below
install,reinstall,remove,upgrade,update,search,cask,list,doctor,edit
# Write "yes" or "no" depending on whether you want to use sudo
no
# Write command to use for root
sudo
# Write a comma separated list of shortcuts below
rm,src,dl,ci,cr,cre
# Write a comma separated list of shortcut mappings from the manager below
remove,search,download,cask install,cask remove,cask reinstall

View File

@@ -1,12 +0,0 @@
# Write the name of the package manager in all lowercase below
aptman
# Write a comma separated list of commands from the manager below
install,remove,upgrade,update,refresh,autoremove,search,filesearch,list
# Write "yes" or "no" depending on whether you want to use sudo
yes
# Write command to use for root
sudo
# Write a comma separated list of shortcuts below
rm,arm,ls
# Write a comma separated list of shortcut mappings from the manager below
remove,autoremove,list

View File

@@ -1,13 +0,0 @@
# Write the name of the package manager in all lowercase below
snap
# Write a comma separated list of commands from the manager below
install,remove,refresh,revert,run,download
# Write "yes" or "no" depending on whether you want to use sudo
yes
# Write command to use for root
sudo
# Write a comma separated list of shortcuts below
rm,inst
# Write a comma separated list of shortcut mappings from the manager below
remove,install

View File

@@ -1,12 +0,0 @@
# Write the name of the package manager in all lowercase below
aptyay
# Write a comma separated list of commands from the manager below
install,remove,upgrade,update,refresh,autoremove,search,filesearch,list,interactive
# Write "yes" or "no" depending on whether you want to use sudo
no
# Write command to use for root
sudo
# Write a comma separated list of shortcuts below
rm,arm,ls,int
# Write a comma separated list of shortcut mappings from the manager below
remove,autoremove,list,interactive

View File

@@ -1,13 +0,0 @@
# Write the name of the package manager in all lowercase below
zypper
# Write a comma separated list of commands from the manager below
install,remove,refresh,search,update,addrepo
# Write "yes" or "no" depending on whether you want to use sudo
yes
# Write command to use for root
sudo
# Write a comma separated list of shortcuts below
rm,ar,inst
# Write a comma separated list of shortcut mappings from the manager below
remove,addrepo,install

View File

@@ -1,39 +0,0 @@
package main
// Remove an element at an index from a slice
func removeAtIndex(s []string, index int) []string {
return append(s[:index], s[index+1:]...)
}
// Check if slice contains string
func Contains(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}
func Max(array []float64) float64 {
var max = array[0]
var min = array[0]
for _, value := range array {
if max < value {
max = value
}
if min > value {
min = value
}
}
return max
}
func Find(slice []string, val string) int {
for i, item := range slice {
if item == val {
return i
}
}
return -1
}

View File

@@ -2,23 +2,35 @@ package main
import (
"fmt"
"strings"
)
// Print help screen
func printHelpMessage(packageManagerCommand string, useRootBool bool, rootCommand string, commands []string, shortcuts []string) {
func printHelpMessage(packageManagerCommand, rootCommand string, commands, shortcuts map[string]string, useRoot, isOverridden bool) {
fmt.Println("Arsen Musayelyan's Package Manager Wrapper")
fmt.Println("Current package manager is:", packageManagerCommand)
if useRootBool { fmt.Println("Using root with command:", rootCommand) } else { fmt.Println("Not using root") }
fmt.Print("Current package manager is: ", packageManagerCommand)
if isOverridden {
fmt.Println(" (overridden)")
} else {
fmt.Print("\n")
}
if useRoot {
fmt.Println("Using root with command:", rootCommand)
} else {
fmt.Println("Not using root")
}
fmt.Println()
fmt.Println("Usage: pak <command> [package]")
fmt.Println("Example: pak in hello")
fmt.Println()
fmt.Println("The available commands are:")
fmt.Println(strings.Join(commands, "\n"))
for command, mapping := range commands {
fmt.Println(command+":", mapping)
}
fmt.Println()
fmt.Println("The available shortcuts are:")
fmt.Println(strings.Join(shortcuts, "\n"))
for shortcut, mapping := range shortcuts {
fmt.Println(shortcut+":", mapping)
}
fmt.Println()
fmt.Println("The available flags are:")
fmt.Println("--help, -h: Shows this help screen")