This repository was archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (42 loc) · 1.18 KB
/
main.go
File metadata and controls
48 lines (42 loc) · 1.18 KB
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
// Copyright (c) 2017–2021 Stefan Fischer
// Use of this code is governed by the MIT license, which can be found in the LICENSE file.
package datautils
import (
"bufio"
"fmt"
"os"
"github.com/urfave/cli"
)
func processStdin(c *cli.Context, process func(string) error) error {
if c.NArg() != 0 {
return cli.NewExitError("Command does not take any arguments!", 1)
}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
if err := process(line); err != nil {
return err
}
}
err := scanner.Err()
return err
}
// DefaultApp TODO
func DefaultApp(version, date, goVersion string) *cli.App {
app := cli.NewApp()
dateTime := ParseRFCDate(date).Format("2006-01-02")
app.Version = fmt.Sprintf("%s (%s, %s)", version, dateTime, goVersion)
app.Copyright = "Copyright (c) 2017–2021 Stefan Fischer"
app.Author = "Stefan Fischer"
app.Email = "sfischer13@ymail.com"
app.HideHelp = true
return app
}
// TransformStdin applies a string transformation function to stdin.
func TransformStdin(c *cli.Context, transform func(string) string) error {
process := func(s string) error {
fmt.Println(transform(s))
return nil
}
return processStdin(c, process)
}