File: main.go

package info (click to toggle)
golang-vbom-util 0.0~git20180919.efcd4e0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 184 kB
  • sloc: makefile: 3
file content (26 lines) | stat: -rw-r--r-- 581 bytes parent folder | download | duplicates (2)
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
// short-regexp is a command-line utility that reads strings from standard input
// (one per line) and outputs a regexp that matches only those strings.
package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"strings"

	"vbom.ml/util"
)

func main() {
	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %s", err)
		os.Exit(1)
	}
	lines := strings.Split(string(data), "\n")
	// Remove trailing empty line if present
	if N := len(lines); N > 0 && lines[N-1] == "" {
		lines = lines[:N-1]
	}
	os.Stdout.WriteString(util.ShortRegexpString(lines...))
}