Skip to content

Commit e0a94c3

Browse files
committed
cycle
1 parent e489546 commit e0a94c3

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

clickerd/cli/main.go

+48-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import (
1212
"net/url"
1313
"os"
1414
"strconv"
15+
"time"
1516
)
1617

17-
var cloudHost string
18-
var cloudPort int
18+
var cloudHost = "localhost"
19+
var cloudPort = 9000
1920
var configFile string
21+
var cycleRepeat bool
22+
var cycleLength int64
2023

2124
func main() {
2225
app := cli.NewApp()
@@ -69,6 +72,28 @@ func main() {
6972
}},
7073
Action: click,
7174
},
75+
{
76+
Name: "cycle",
77+
Usage: "Click each item in the list",
78+
UsageText: "clicker cycle",
79+
Description: "Show model of item.",
80+
Flags: []cli.Flag{
81+
&cli.BoolFlag{
82+
Name: "repeat",
83+
Value: false,
84+
Usage: "Repeat the list",
85+
Aliases: []string{"r"},
86+
Destination: &cycleRepeat,
87+
},
88+
&cli.Int64Flag{
89+
Name: "length",
90+
Value: 30,
91+
Usage: "Length in seconds",
92+
Aliases: []string{"l"},
93+
Destination: &cycleLength,
94+
}},
95+
Action: cycle,
96+
},
7297
}
7398

7499
err := app.Run(os.Args)
@@ -182,3 +207,24 @@ func call(item *Item) error {
182207
}
183208
return nil
184209
}
210+
211+
func cycle(c *cli.Context) error {
212+
cfg, e := parseClickerConf()
213+
if e != nil {
214+
log.Printf("failed to read clicker configuration")
215+
return e
216+
}
217+
218+
for {
219+
for idx, item := range cfg.Items {
220+
fmt.Printf("\t%v. %v\n", idx+1, item.Title)
221+
e = call(&item)
222+
time.Sleep(time.Duration(cycleLength) * time.Second)
223+
}
224+
if !cycleRepeat {
225+
break
226+
}
227+
}
228+
229+
return nil
230+
}

clickerd/etc/clicker-cycle.service

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Clicker Cycle
3+
4+
[Service]
5+
Type=simple
6+
ExecStart=/usr/local/bin/clicker cycle -l 10 -r
7+
8+
[Install]
9+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)