add --json flag to hyprman mako
This commit is contained in:
parent
b31326b529
commit
68c90481fc
4 changed files with 26 additions and 13 deletions
|
@ -1,24 +1,26 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"git.dayl.in/daylin/hyprman/internal"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
hyprman "git.dayl.in/daylin/hyprman/internal"
|
||||
)
|
||||
|
||||
var makoCmd = &cobra.Command{
|
||||
Use: "mako",
|
||||
Short: "mako integration",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
hyprman.ListNotifications(number)
|
||||
hyprman.ListNotifications(number, json)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
var (
|
||||
number int
|
||||
json bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(makoCmd)
|
||||
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 (
|
||||
"os"
|
||||
|
||||
"git.dayl.in/daylin/hyprman/internal"
|
||||
cc "github.com/ivanpirog/coloredcobra"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
hyprman "git.dayl.in/daylin/hyprman/internal"
|
||||
)
|
||||
|
||||
func Execute() {
|
||||
|
|
|
@ -69,14 +69,24 @@ func getHistory() History {
|
|||
return makoHistory.toHistory()
|
||||
}
|
||||
|
||||
func ListNotifications(number int) {
|
||||
history := getHistory()
|
||||
for i, n := range history.Notifications {
|
||||
if i > number-1 {
|
||||
break
|
||||
func (h *History) truncate(number int) {
|
||||
h.Notifications = h.Notifications[:min(len(h.Notifications), number)]
|
||||
}
|
||||
|
||||
func ListNotifications(number int, outputJson bool) {
|
||||
history := getHistory()
|
||||
history.truncate(number)
|
||||
if !outputJson {
|
||||
for _, n := range history.Notifications {
|
||||
n.Render()
|
||||
}
|
||||
} else {
|
||||
b, err := json.MarshalIndent(history.Notifications, "", " ")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
}
|
||||
|
||||
func (n Notifcation) Render() {
|
||||
|
|
Loading…
Reference in a new issue