-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy patharea.go
69 lines (57 loc) · 1.29 KB
/
area.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package radigo
import (
"context"
"flag"
"fmt"
"os"
"strings"
"github.com/mitchellh/cli"
"github.com/olekukonko/tablewriter"
"github.com/yyoshiki41/go-radiko"
)
type areaCommand struct {
ui cli.Ui
}
func (c *areaCommand) Run(args []string) int {
var areaID string
f := flag.NewFlagSet("area", flag.ContinueOnError)
f.StringVar(&areaID, "id", "", "id")
f.Usage = func() { c.ui.Error(c.Help()) }
if err := f.Parse(args); err != nil {
return 1
}
client, err := radiko.New("")
if err != nil {
c.ui.Error(fmt.Sprintf(
"Failed to construct a radiko Client.: %s", err))
return 1
}
if areaID != "" {
client.SetAreaID(areaID)
}
stations, err := client.GetNowPrograms(context.Background())
if err != nil {
c.ui.Error(fmt.Sprintf(
"Failed to get stations: %s", err))
return 1
}
c.ui.Output(fmt.Sprintf(" Area ID: %s", client.AreaID()))
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Station ID"})
for _, s := range stations {
table.Append([]string{s.Name, s.ID})
}
table.Render()
return 0
}
func (c *areaCommand) Synopsis() string {
return "Get available station ids"
}
func (c *areaCommand) Help() string {
return strings.TrimSpace(`
Usage: radigo area [options]
Get available stations ids.
Options:
-id=name Area id
`)
}