-
Notifications
You must be signed in to change notification settings - Fork 21
/
manual.go
39 lines (33 loc) · 921 Bytes
/
manual.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
package helper
import (
"fmt"
"strings"
"github.com/awslabs/tecli/box"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
)
// Manual mapping the fields used by a Cobra command
type Manual struct {
Use string `yaml:"use,omitempty"`
Example string `yaml:"example,omitempty"`
Short string `yaml:"short,omitempty"`
Long string `yaml:"long,omitempty"`
}
//GetManual returns the command's manuall
func GetManual(command string, args []string) (Manual, error) {
var man Manual
var err error
manualBlob, status := box.Get("/manual/" + command + ".yaml")
if status {
err = yaml.Unmarshal(manualBlob, &man)
if err != nil {
return man, fmt.Errorf("unable to decode YAML file, error:\n%v", err)
}
} else {
logrus.Fatal("unable to read manual from box")
}
if man.Use != "" {
man.Use = strings.ReplaceAll(man.Use, "{{ arguments }}", "["+strings.Join(args, "|")+"]")
}
return man, err
}