add --json flag to hyprman mako
This commit is contained in:
parent
b31326b529
commit
68c90481fc
4 changed files with 26 additions and 13 deletions
|
@ -8,8 +8,8 @@ var ewwCmd = &cobra.Command{
|
||||||
Use: "eww",
|
Use: "eww",
|
||||||
Short: "eww integration",
|
Short: "eww integration",
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
hm.LoadConfig(configPath)
|
hm.LoadConfig(configPath)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
12
cmd/mako.go
12
cmd/mako.go
|
@ -1,24 +1,26 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dayl.in/daylin/hyprman/internal"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
hyprman "git.dayl.in/daylin/hyprman/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var makoCmd = &cobra.Command{
|
var makoCmd = &cobra.Command{
|
||||||
Use: "mako",
|
Use: "mako",
|
||||||
Short: "mako integration",
|
Short: "mako integration",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
hyprman.ListNotifications(number)
|
hyprman.ListNotifications(number, json)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
number int
|
number int
|
||||||
|
json bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(makoCmd)
|
rootCmd.AddCommand(makoCmd)
|
||||||
makoCmd.Flags().IntVarP(&number, "number", "n", 10, "number of notifications")
|
makoCmd.Flags().IntVarP(&number, "number", "n", 10, "number of notifications")
|
||||||
|
makoCmd.Flags().BoolVar(&json, "json", false, "output data as json")
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.dayl.in/daylin/hyprman/internal"
|
|
||||||
cc "github.com/ivanpirog/coloredcobra"
|
cc "github.com/ivanpirog/coloredcobra"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
hyprman "git.dayl.in/daylin/hyprman/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
|
|
|
@ -69,13 +69,23 @@ func getHistory() History {
|
||||||
return makoHistory.toHistory()
|
return makoHistory.toHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListNotifications(number int) {
|
func (h *History) truncate(number int) {
|
||||||
|
h.Notifications = h.Notifications[:min(len(h.Notifications), number)]
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListNotifications(number int, outputJson bool) {
|
||||||
history := getHistory()
|
history := getHistory()
|
||||||
for i, n := range history.Notifications {
|
history.truncate(number)
|
||||||
if i > number-1 {
|
if !outputJson {
|
||||||
break
|
for _, n := range history.Notifications {
|
||||||
|
n.Render()
|
||||||
}
|
}
|
||||||
n.Render()
|
} else {
|
||||||
|
b, err := json.MarshalIndent(history.Notifications, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Println(string(b))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue