github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/buildtools/bundler/bundler.go (about) 1 package bundler 2 3 import ( 4 "strings" 5 6 "github.com/apex/log" 7 8 "github.com/fossas/fossa-cli/exec" 9 ) 10 11 type Bundler struct { 12 Cmd string 13 } 14 15 type Gem struct { 16 Name string 17 Revision string 18 } 19 20 func (b *Bundler) List() ([]Gem, error) { 21 stdout, _, err := exec.Run(exec.Cmd{ 22 Name: b.Cmd, 23 Argv: []string{"list"}, 24 }) 25 if err != nil { 26 return nil, err 27 } 28 contents := strings.TrimSpace(strings.TrimPrefix(stdout, "Gems included by the bundle:\n")) 29 lines := strings.Split(contents, "\n") 30 var gems []Gem 31 for _, line := range lines[1:] { // The first line is "Gems included by the bundle:" 32 trimmed := strings.TrimPrefix(line, " * ") 33 log.WithField("trimmed", trimmed).Debug("parsing line") 34 sections := strings.Split(trimmed, " ") 35 gems = append(gems, Gem{ 36 Name: sections[0], 37 Revision: sections[1], 38 }) 39 } 40 return gems, nil 41 } 42 43 func (b *Bundler) Install(flags ...string) error { 44 if flags == nil { 45 flags = []string{"--frozen", "--deployment"} 46 } 47 _, _, err := exec.Run(exec.Cmd{ 48 Name: b.Cmd, 49 Argv: append([]string{"install"}, flags...), 50 }) 51 return err 52 }