-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.go
46 lines (37 loc) · 1.09 KB
/
random.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package command
import (
"os"
"github.com/spf13/cobra"
"github.com/virtualtam/walric/cmd/walric/formatter"
"github.com/virtualtam/walric/pkg/history"
"github.com/virtualtam/walric/pkg/monitor"
)
// NewRandomCommand initializes a CLI command to select a random submission
// suitable for the current monitor setup.
func NewRandomCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "random",
Short: "Select a random submission suitable for the current monitor setup",
Run: func(cmd *cobra.Command, args []string) {
monitors, err := monitor.ConnectedMonitors(xRandRScreenNo)
if err != nil {
cobra.CheckErr(err)
}
wallpaperResolution := monitor.WallpaperResolution(monitors)
submission, err := submissionService.Random(wallpaperResolution)
if err != nil {
cobra.CheckErr(err)
}
entry, err := history.NewEntry(submission)
if err != nil {
cobra.CheckErr(err)
}
if err := historyService.Save(entry); err != nil {
cobra.CheckErr(err)
}
writer := formatter.FormatSubmissionAsTab(os.Stdout, submission)
writer.Flush()
},
}
return cmd
}