hyprland: add HyprlandManager

parent fcb380e1
package config
type ctxKey string
const HyprManagerKey ctxKey = "hyprManager"
...@@ -13,6 +13,23 @@ func CommandList() *cli.Command { ...@@ -13,6 +13,23 @@ func CommandList() *cli.Command {
Name: "hyprland", Name: "hyprland",
Hidden: config.Env.Hyprland == nil, Hidden: config.Env.Hyprland == nil,
Usage: "Hyprland Management", Usage: "Hyprland Management",
Before: func(ctx context.Context, command *cli.Command) (context.Context, error) {
manager, err := NewHyprlandManager()
if err != nil {
return ctx, fmt.Errorf("не удалось инициализировать HyprlandManager: %w", err)
}
ctx = context.WithValue(ctx, config.HyprManagerKey, manager)
return ctx, nil
},
After: func(ctx context.Context, command *cli.Command) error {
manager, err := GetHyprlandManager(ctx)
if err != nil {
return fmt.Errorf("не удалось инициализировать HyprlandManager: %w", err)
}
manager.Save()
return nil
},
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "check", Name: "check",
...@@ -202,9 +219,12 @@ func ShellCompleteVarList(ctx context.Context, cmd *cli.Command) { ...@@ -202,9 +219,12 @@ func ShellCompleteVarList(ctx context.Context, cmd *cli.Command) {
if cmd.NArg() > 0 { if cmd.NArg() > 0 {
return return
} }
data, _ := hyprlandVarList() manager, _ := NewHyprlandManager()
for _, t := range data {
fmt.Println(t) data := manager.Vars
for _, v := range data {
fmt.Println(v.Name)
} }
} }
...@@ -213,10 +233,11 @@ func ShellCompleteModule(filter string) func(ctx context.Context, cmd *cli.Comma ...@@ -213,10 +233,11 @@ func ShellCompleteModule(filter string) func(ctx context.Context, cmd *cli.Comma
if cmd.NArg() > 0 { if cmd.NArg() > 0 {
return return
} }
manager, _ := NewHyprlandManager()
userFlag := cmd.Bool("user") userFlag := cmd.Bool("user")
data := hyprlandListModules(userFlag, filter) data := manager.GetModulesList(userFlag, filter)
for _, t := range data { for _, t := range data {
fmt.Println(t) fmt.Println(t)
} }
...@@ -229,7 +250,9 @@ func ShellCompletePlugin(filter string) func(ctx context.Context, cmd *cli.Comma ...@@ -229,7 +250,9 @@ func ShellCompletePlugin(filter string) func(ctx context.Context, cmd *cli.Comma
return return
} }
data := hyprlandPluginList(filter) manager, _ := NewHyprlandManager()
data := manager.GetPluginsList(filter)
for _, t := range data { for _, t := range data {
fmt.Println(t) fmt.Println(t)
} }
......
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