2023-01-18 18:42:08 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
2023-06-05 20:37:41 +02:00
|
|
|
|
|
|
|
"pikman/command"
|
2023-01-19 14:45:24 +01:00
|
|
|
"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() {
|
2023-01-20 21:05:16 +01:00
|
|
|
if os.Getuid() == 0 {
|
|
|
|
log.Fatalf("Error: Do not run pikman as root")
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:37:41 +02:00
|
|
|
cmd := &command.Command{
|
|
|
|
OsType: types.Ubuntu,
|
|
|
|
ContainerName: "",
|
|
|
|
IsUpgradable: false,
|
|
|
|
IsJSON: false,
|
|
|
|
IsInstalled: false,
|
|
|
|
PackageName: make([]string, 0),
|
|
|
|
}
|
|
|
|
|
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",
|
2023-06-05 21:13:53 +02:00
|
|
|
Version: "v1.23.6.5.2",
|
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 {
|
2023-06-05 20:37:41 +02:00
|
|
|
cmd.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 {
|
2023-06-05 20:37:41 +02:00
|
|
|
cmd.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 {
|
2023-06-05 20:37:41 +02:00
|
|
|
cmd.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 {
|
2023-06-05 20:37:41 +02:00
|
|
|
cmd.OsType = types.Flatpak
|
2023-01-18 18:42:08 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "name",
|
|
|
|
Usage: "Name of the managed container",
|
2023-06-05 20:37:41 +02:00
|
|
|
Destination: &cmd.ContainerName,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "autoremove",
|
|
|
|
Usage: "Remove all unused packages",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "clean",
|
|
|
|
Aliases: []string{"cl"},
|
|
|
|
Usage: "Clean the package manager cache",
|
2023-06-05 20:37:41 +02:00
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "enter",
|
|
|
|
Usage: "Enter the container instance for select package manager",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "export",
|
|
|
|
Usage: "Export/Recreate a program's desktop entry from the container",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "init",
|
|
|
|
Usage: "Initialize a managed container",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "install",
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
Usage: "Install the specified package(s)",
|
2023-06-05 20:37:41 +02:00
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"l"},
|
|
|
|
Usage: "List installed packages",
|
2023-02-17 14:58:50 +01:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "upgradable",
|
|
|
|
Usage: "Used by list to check upgradable packages",
|
2023-06-05 20:37:41 +02:00
|
|
|
Destination: &cmd.IsUpgradable,
|
2023-02-17 14:58:50 +01:00
|
|
|
},
|
2023-03-09 19:04:42 +01:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "installed",
|
|
|
|
Usage: "Used by list to check installed packages",
|
2023-06-05 20:37:41 +02:00
|
|
|
Destination: &cmd.IsInstalled,
|
2023-03-09 19:04:42 +01:00
|
|
|
},
|
2023-02-17 14:58:50 +01:00
|
|
|
},
|
2023-06-05 20:37:41 +02:00
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "log",
|
|
|
|
Usage: "Show package manager logs",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "purge",
|
|
|
|
Usage: "Fully purge a package",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "run",
|
|
|
|
Usage: "Run a command inside a managed container",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "remove",
|
|
|
|
Aliases: []string{"r"},
|
|
|
|
Usage: "Remove an installed package",
|
2023-06-05 20:37:41 +02:00
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "search",
|
|
|
|
Aliases: []string{"s"},
|
|
|
|
Usage: "Search for a package",
|
2023-06-05 20:37:41 +02:00
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "show",
|
|
|
|
Usage: "Show details for a package",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "unexport",
|
|
|
|
Usage: "Unexport/Remove a program's desktop entry",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "update",
|
|
|
|
Usage: "Update the list of available packages",
|
|
|
|
Action: cmd.Process,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "upgrade",
|
|
|
|
Usage: "Upgrade the system by installing/upgrading available packages",
|
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-05 20:37:41 +02:00
|
|
|
Name: "upgrades",
|
|
|
|
Usage: "List the available upgrades",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "json",
|
|
|
|
Usage: "Output in JSON",
|
|
|
|
Destination: &cmd.IsJSON,
|
|
|
|
},
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
2023-06-05 20:37:41 +02:00
|
|
|
Action: cmd.Process,
|
2023-01-18 18:42:08 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Suggest = true
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|