-
Notifications
You must be signed in to change notification settings - Fork 2
/
passarg.go
49 lines (42 loc) · 988 Bytes
/
passarg.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
package main
import (
"errors"
"sort"
"strings"
"github.com/qawatake/obsdconv/process"
)
type argPasserImpl struct {
title bool
alias bool
}
func newArgPasserImpl(title bool, alias bool) *argPasserImpl {
return &argPasserImpl{
title: title,
alias: alias,
}
}
func (passer *argPasserImpl) PassArg(frombody process.BodyConvAuxOut) (toyaml process.YamlConvAuxIn, err error) {
title := ""
alias := ""
var newtags []string
// fetch
args, ok := frombody.(*bodyConvAuxOutImpl)
if !ok {
return nil, errors.New("frombody (process.BodyConvAuxOutImpl) cannot converted to process.YamlConvAuxInImpl")
}
if passer.title {
title = args.title
}
if passer.alias {
alias = args.title
}
newtags = make([]string, 0, len(args.tags))
for tg := range args.tags {
newtags = append(newtags, tg)
}
// sort tags
sort.Slice(newtags, func(i, j int) bool {
return strings.Compare(newtags[i], newtags[j]) <= 0
})
return newYamlConvAuxInImpl(title, alias, newtags), nil
}