pikman/main.go

224 lines
6.2 KiB
Go
Raw Permalink Normal View History

2023-01-18 18:42:08 +01:00
package main
import (
"log"
"os"
"pikman/loader"
"pikman/types"
2023-03-09 19:04:42 +01:00
"github.com/urfave/cli/v2"
2023-01-18 18:42:08 +01:00
)
func main() {
if os.Getuid() == 0 {
log.Fatalf("Error: Do not run pikman as root")
}
osType := types.Ubuntu
2023-01-18 18:42:08 +01:00
containerName := ""
upgradableFlag := false
2023-03-09 19:04:42 +01:00
installedFlag := false
2023-01-18 18:42:08 +01:00
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Version number",
}
app := &cli.App{
Name: "pikman",
Usage: "One package manager to rule them all",
Version: "v1.23.2.17.0",
2023-01-18 18:42:08 +01:00
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "arch",
Aliases: []string{"aur"},
Usage: "Install Arch packages (including from the AUR)",
Action: func(cCtx *cli.Context, b bool) error {
if b {
osType = types.Arch
2023-01-18 18:42:08 +01:00
}
return nil
},
},
&cli.BoolFlag{
Name: "fedora",
Aliases: []string{"dnf"},
Usage: "Install Fedora packages",
Action: func(cCtx *cli.Context, b bool) error {
if b {
osType = types.Fedora
2023-01-18 18:42:08 +01:00
}
return nil
},
},
&cli.BoolFlag{
Name: "alpine",
Aliases: []string{"apk"},
Usage: "Install Alpine packages",
Action: func(cCtx *cli.Context, b bool) error {
if b {
osType = types.Alpine
2023-01-18 18:42:08 +01:00
}
return nil
},
},
&cli.BoolFlag{
Name: "flatpak",
Aliases: []string{"fl"},
Usage: "Install Flatpak packages",
Action: func(cCtx *cli.Context, b bool) error {
if b {
osType = types.Flatpak
2023-01-18 18:42:08 +01:00
}
return nil
},
},
&cli.StringFlag{
Name: "name",
Usage: "Name of the managed container",
Destination: &containerName,
},
},
Commands: []*cli.Command{
{
Name: "autoremove",
Usage: "Remove all unused packages",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "clean",
Aliases: []string{"cl"},
Usage: "Clean the package manager cache",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "enter",
Usage: "Enter the container instance for select package manager",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "export",
Usage: "Export/Recreate a program's desktop entry from the container",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "init",
Usage: "Initialize a managed container",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "install",
Aliases: []string{"i"},
Usage: "Install the specified package(s)",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "list",
Aliases: []string{"l"},
Usage: "List installed packages",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "upgradable",
Usage: "Used by list to check upgradable packages",
Destination: &upgradableFlag,
},
2023-03-09 19:04:42 +01:00
&cli.BoolFlag{
Name: "installed",
Usage: "Used by list to check installed packages",
Destination: &installedFlag,
},
},
2023-01-18 18:42:08 +01:00
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), upgradableFlag, installedFlag)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "log",
Usage: "Show package manager logs",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "purge",
Usage: "Fully purge a package",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "run",
Usage: "Run a command inside a managed container",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "remove",
Aliases: []string{"r"},
Usage: "Remove an installed package",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "search",
Aliases: []string{"s"},
Usage: "Search for a package",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "show",
Usage: "Show details for a package",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "unexport",
Usage: "Unexport/Remove a program's desktop entry",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "update",
Usage: "Update the list of available packages",
Action: func(cCtx *cli.Context) error {
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
{
Name: "upgrade",
Usage: "Upgrade the system by installing/upgrading available packages",
Action: func(cCtx *cli.Context) error {
cCtx.Args().Tail()
2023-03-09 19:04:42 +01:00
return loader.ProcessCommand(cCtx.Command.FullName(), osType, containerName, cCtx.Args().Slice(), false, false)
2023-01-18 18:42:08 +01:00
},
},
},
}
app.Suggest = true
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}