add base app

parents
package config
import (
"os"
"path/filepath"
)
type HyprEnv struct {
Config string
}
type Environment struct {
Version string
Hyprland *HyprEnv
}
var Env Environment
func InitConfig() error {
Env.Version = "0.1.0"
if _, err := os.Stat("/usr/bin/Hyprland"); os.IsNotExist(err) {
Env.Hyprland = nil
} else {
Env.Hyprland = &HyprEnv{}
}
home, _ := os.UserHomeDir()
if Env.Hyprland != nil {
confPath := filepath.Join(home, ".config", "hypr", "hyprland.conf")
if _, err := os.Stat(confPath); err == nil {
Env.Hyprland.Config = confPath
} else {
Env.Hyprland.Config = ""
}
}
return nil
}
module ximperconf
go 1.25.0
require github.com/urfave/cli/v3 v3.4.1
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package hyprland
import (
"context"
"fmt"
"ximperconf/config"
"os/exec"
"strings"
"github.com/urfave/cli/v3"
)
func CheckHyprland(ctx context.Context, cmd *cli.Command) error {
h := config.Env.Hyprland
if h == nil || h.Config == "" {
fmt.Println("")
}
command := exec.Command("hyprland", "--verify-config")
output, err := command.CombinedOutput()
if err != nil {
fmt.Println("")
}
lines := strings.Split(string(output), "\n")
result := []string{}
start := false
for _, line := range lines {
if strings.Contains(line, "======== Config parsing result:") {
start = true
continue
}
if start && strings.TrimSpace(line) != "" {
result = append(result, line)
}
}
fmt.Println(strings.Join(result, "\n"))
return nil
}
package hyprland
import (
"ximperconf/config"
"github.com/urfave/cli/v3"
)
func CommandList() *cli.Command {
return &cli.Command{
Name: "hyprland",
Aliases: []string{"h"},
Hidden: config.Env.Hyprland == nil,
Usage: "Hyprland Management",
Commands: []*cli.Command{
{
Name: "check",
Usage: "Check the Hyprland config",
Action: CheckHyprland,
},
},
}
}
package main
import (
"context"
"os"
"ximperconf/config"
"ximperconf/hyprland"
"github.com/urfave/cli/v3"
)
func main() {
config.InitConfig()
rootCommand := &cli.Command{
Name: "ximperconf",
Usage: "Ximper Linux Configuration Tool",
EnableShellCompletion: true,
Version: config.Env.Version,
Commands: []*cli.Command{
hyprland.CommandList(),
{
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
ArgsUsage: "[command]",
HideHelp: true,
},
},
}
if err := rootCommand.Run(context.Background(), os.Args); err != nil {
os.Exit(1)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment