-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
49 lines (44 loc) · 993 Bytes
/
info.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 (
"context"
"flag"
"fmt"
"github.com/hokaccha/go-prettyjson"
"go.uber.org/multierr"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"moul.io/u"
)
func doInfo(ctx context.Context, args []string) error {
if len(args) < 1 {
return flag.ErrHelp
}
paths := u.UniqueStrings(args)
logger.Debug("doInfo", zap.Any("opts", opts), zap.Strings("project", paths))
var errs error
g, ctx := errgroup.WithContext(ctx)
for _, path := range paths {
path := path
g.Go(func() error {
err := doInfoOnce(ctx, path)
if err != nil {
errs = multierr.Append(errs, fmt.Errorf("%q: %w", path, err))
}
return nil
})
}
_ = g.Wait()
return errs
}
func doInfoOnce(_ context.Context, path string) error {
project, err := projectFromPath(path)
if err != nil {
return fmt.Errorf("invalid project: %w", err)
}
s, err := prettyjson.Marshal(project)
if err != nil {
return fmt.Errorf("json marshal error: %w", err)
}
fmt.Println(string(s))
return nil
}