Add installed flag to list

This commit is contained in:
ferrreo 2023-03-09 18:04:42 +00:00
parent 1dc9d2158f
commit f4e62e661f
2 changed files with 29 additions and 19 deletions

View File

@ -29,7 +29,7 @@ var packageManagerMap = map[types.OSType]string{
types.Flatpak: flatpak.PackageManager, types.Flatpak: flatpak.PackageManager,
} }
func ProcessCommand(command string, osType types.OSType, containerName string, packageName []string, upgradableFlag bool) error { func ProcessCommand(command string, osType types.OSType, containerName string, packageName []string, upgradableFlag bool, installedFlag bool) error {
var err error var err error
if osType != types.Ubuntu && osType != types.Flatpak && containerName != "" { if osType != types.Ubuntu && osType != types.Flatpak && containerName != "" {
packageName = append([]string{"--name " + containerName}, packageName...) packageName = append([]string{"--name " + containerName}, packageName...)
@ -39,6 +39,10 @@ func ProcessCommand(command string, osType types.OSType, containerName string, p
packageName = append([]string{"--upgradable"}, packageName...) packageName = append([]string{"--upgradable"}, packageName...)
} }
if osType == types.Ubuntu && installedFlag {
packageName = append([]string{"--installed"}, packageName...)
}
commandToExecute, err := getCommand(command, osType, packageName) commandToExecute, err := getCommand(command, osType, packageName)
cmd := exec.Command("/bin/sh", "-c", commandToExecute) cmd := exec.Command("/bin/sh", "-c", commandToExecute)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout

42
main.go
View File

@ -1,11 +1,12 @@
package main package main
import ( import (
"github.com/urfave/cli/v2"
"log" "log"
"os" "os"
"pikman/loader" "pikman/loader"
"pikman/types" "pikman/types"
"github.com/urfave/cli/v2"
) )
func main() { func main() {
@ -17,7 +18,7 @@ func main() {
osType := types.Ubuntu osType := types.Ubuntu
containerName := "" containerName := ""
upgradableFlag := false upgradableFlag := false
installedFlag := false
cli.VersionFlag = &cli.BoolFlag{ cli.VersionFlag = &cli.BoolFlag{
Name: "version", Name: "version",
Aliases: []string{"v"}, Aliases: []string{"v"},
@ -85,7 +86,7 @@ func main() {
Name: "autoremove", Name: "autoremove",
Usage: "Remove all unused packages", Usage: "Remove all unused packages",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
@ -93,28 +94,28 @@ func main() {
Aliases: []string{"cl"}, Aliases: []string{"cl"},
Usage: "Clean the package manager cache", Usage: "Clean the package manager cache",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "enter", Name: "enter",
Usage: "Enter the container instance for select package manager", Usage: "Enter the container instance for select package manager",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "export", Name: "export",
Usage: "Export/Recreate a program's desktop entry from the container", Usage: "Export/Recreate a program's desktop entry from the container",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "init", Name: "init",
Usage: "Initialize a managed container", Usage: "Initialize a managed container",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
@ -122,7 +123,7 @@ func main() {
Aliases: []string{"i"}, Aliases: []string{"i"},
Usage: "Install the specified package(s)", Usage: "Install the specified package(s)",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
@ -135,30 +136,35 @@ func main() {
Usage: "Used by list to check upgradable packages", Usage: "Used by list to check upgradable packages",
Destination: &upgradableFlag, Destination: &upgradableFlag,
}, },
&cli.BoolFlag{
Name: "installed",
Usage: "Used by list to check installed packages",
Destination: &installedFlag,
},
}, },
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), upgradableFlag) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), upgradableFlag, installedFlag)
}, },
}, },
{ {
Name: "log", Name: "log",
Usage: "Show package manager logs", Usage: "Show package manager logs",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "purge", Name: "purge",
Usage: "Fully purge a package", Usage: "Fully purge a package",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "run", Name: "run",
Usage: "Run a command inside a managed container", Usage: "Run a command inside a managed container",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
@ -166,7 +172,7 @@ func main() {
Aliases: []string{"r"}, Aliases: []string{"r"},
Usage: "Remove an installed package", Usage: "Remove an installed package",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
@ -174,28 +180,28 @@ func main() {
Aliases: []string{"s"}, Aliases: []string{"s"},
Usage: "Search for a package", Usage: "Search for a package",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "show", Name: "show",
Usage: "Show details for a package", Usage: "Show details for a package",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "unexport", Name: "unexport",
Usage: "Unexport/Remove a program's desktop entry", Usage: "Unexport/Remove a program's desktop entry",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
Name: "update", Name: "update",
Usage: "Update the list of available packages", Usage: "Update the list of available packages",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
{ {
@ -203,7 +209,7 @@ func main() {
Usage: "Upgrade the system by installing/upgrading available packages", Usage: "Upgrade the system by installing/upgrading available packages",
Action: func(cCtx *cli.Context) error { Action: func(cCtx *cli.Context) error {
cCtx.Args().Tail() cCtx.Args().Tail()
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false) return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
}, },
}, },
}, },