-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquerybuf.go
45 lines (39 loc) · 895 Bytes
/
querybuf.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
package main
import (
"flag"
"fmt"
"os"
"strconv"
"github.com/scgolang/sc"
)
// QueryBuf queries for information about a buffer.
type QueryBuf struct {
flagErrorHandling flag.ErrorHandling
scc *sc.Client
}
// Run runs the command.
func (qb QueryBuf) Run(args []string) error {
if numargs := len(args); numargs == 0 {
return ErrUsage
}
num, err := strconv.ParseInt(args[0], 10, 32)
if err != nil {
return ErrUsage
}
buf, err := qb.scc.QueryBuffer(int32(num))
if err != nil {
return err
}
printBuf(buf)
return nil
}
// Usage prints out a usage message.
func (qb QueryBuf) Usage() {
fmt.Fprint(os.Stderr, `
scc [GLOBAL OPTIONS] querybuf NUM
`)
}
func printBuf(buf *sc.Buffer) {
fmt.Printf("%-20s%-20s%-20s%-20s\n", "BUFFER", "CHANNELS", "FRAMES", "SAMPLE RATE")
fmt.Printf("%-20d%-20d%-20d%-20f\n", buf.Num, buf.Channels, buf.Frames, buf.SampleRate)
}