hoster/cmd/hoster_cli/hoster.go

83 lines
1.6 KiB
Go
Raw Normal View History

2024-09-11 11:41:04 +02:00
package hoster_cli
2024-08-28 12:31:17 +02:00
import (
"os"
"os/user"
"path/filepath"
2024-08-28 12:31:17 +02:00
"gitea.codeblob.work/pk/hoster/cmd/hoster_cli/commands"
"gitea.codeblob.work/pk/hoster/internals/conf"
2024-08-28 12:31:17 +02:00
"github.com/kataras/golog"
"github.com/urfave/cli/v2"
)
2024-09-11 11:41:04 +02:00
func Execute() {
conf.LoadConfig(filepath.Join(findHomeDir(), ".hoster.yml"))
2024-08-28 12:31:17 +02:00
app := &cli.App{
2024-08-28 12:42:07 +02:00
Name: "hoster",
Usage: "Hoster",
Version: "1.0.9",
2024-08-28 12:31:17 +02:00
Commands: []*cli.Command{
{
Name: "new",
Usage: "Setup a new hosting project.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "The name of the project",
Required: true,
},
2024-09-12 00:18:40 +02:00
&cli.StringFlag{
Name: "custom-path",
Usage: "The path of the project. Defaults to ${projects.root}/${name}.",
Required: false,
},
2024-08-28 12:31:17 +02:00
&cli.StringFlag{
Name: "domain",
Aliases: []string{"d"},
Usage: "The description of the project",
Required: true,
},
},
Action: commands.CmdNew,
},
{
Name: "check",
Usage: "Check if newer versions of docker images are available",
Action: commands.CmdCheckUpdated,
2024-08-28 12:31:17 +02:00
},
},
}
if err := app.Run(os.Args); err != nil {
golog.Fatal(err)
}
}
func findHomeDir() string {
if os.Getuid() == 0 {
username := os.Getenv("SUDO_USER")
if username == "" {
golog.Fatalf("SUDO_USER environment variable is not set.")
}
u, err := user.Lookup(username)
if err != nil {
golog.Fatal(err)
}
return u.HomeDir
}
dir, err := os.UserHomeDir()
if err != nil {
golog.Fatalf("Error getting home directory: %v", err)
}
return dir
}