forked from lmika/oaipmh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdsets.go
47 lines (40 loc) · 1.23 KB
/
cmdsets.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
package main
import (
"fmt"
"strings"
"flag"
"bufio"
"github.com/lmika-bom/oaipmh/client"
)
// ---------------------------------------------------------------------------------------------------
// Sets commands
type SetsCommand struct {
Ctx *Context
flagDetailed *bool
}
func (lc *SetsCommand) Flags(fs *flag.FlagSet) *flag.FlagSet {
lc.flagDetailed = fs.Bool("l", false, "Use detailed listing format")
return fs
}
func (lc *SetsCommand) Run(args []string) {
lc.Ctx.Session.ListSets(0, -1, func(res oaipmh.OaipmhSet) bool {
if (*(lc.flagDetailed)) {
fmt.Printf("%s: %s\n", res.Spec, res.Name)
descrLines := strings.Split(res.Descr.OaiDC.Descr, "\n")
for _, v := range descrLines {
v = strings.Trim(v, " \n\t")
if (v != "") {
fmt.Println()
scanner := bufio.NewScanner(strings.NewReader(v))
for scanner.Scan() {
fmt.Printf(" %s\n", scanner.Text())
}
fmt.Println()
}
}
} else {
fmt.Printf("%s\n", res.Spec)
}
return true
})
}