diff options
Diffstat (limited to 'describe')
| -rw-r--r-- | describe/describe.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/describe/describe.go b/describe/describe.go new file mode 100644 index 0000000..fe168ec --- /dev/null +++ b/describe/describe.go @@ -0,0 +1,33 @@ +package describe + +import ( + "bufio" + "os" + "strings" +) + +var DescriptionPrefixes = []string{ + "#", + "//", +} + +func Describe(file string) (string, error) { + fd, err := os.Open(file) + if err != nil { + return "", err + } + defer fd.Close() + scanner := bufio.NewScanner(fd) + scanner.Split(bufio.ScanLines) + scanner.Scan() + text := scanner.Text() + if strings.HasPrefix(text, "#!") { + scanner.Scan() + text = scanner.Text() + } + text = strings.TrimSpace(text) + if !strings.HasPrefix(text, "#") { + return "", nil + } + return text, nil +} |
