Skip to content

Commit 20de85f

Browse files
committed
updated the runners
1 parent 6074983 commit 20de85f

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

apps/apps.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"io"
77
"io/ioutil"
8-
"log"
9-
"os"
8+
"log"
9+
"os"
1010
"os/exec"
1111
"strings"
1212

@@ -91,8 +91,8 @@ func (a Apps) brewInstall() error {
9191
defer stdin.Close()
9292
_, err := io.WriteString(stdin, a.SudoPassword)
9393
if err != nil {
94-
log.Fatalf("brew install write sudo: %+v", err)
95-
}
94+
log.Fatalf("brew install write sudo: %+v", err)
95+
}
9696
}()
9797

9898
_, err = c.CombinedOutput()
@@ -139,6 +139,7 @@ func (a Apps) InstallCLI() error {
139139
for _, installer := range apps {
140140
switch installer.Installer {
141141
case "brew":
142+
c := console.NewConsole(false).Start("Brew Installs")
142143
for _, app := range installer.ToInstall {
143144
if installer.Extra == "tap" {
144145
if err := tap(app); err != nil {
@@ -148,39 +149,50 @@ func (a Apps) InstallCLI() error {
148149
}
149150

150151
i := Brew{
151-
App: app,
152+
App: app,
153+
Console: c,
152154
}
153155
if err := Install(i); err != nil {
154156
return fmt.Errorf("brew install: %w", err)
155157
}
156158
}
159+
c.End("Brew Installs")
157160
case "cask":
161+
c := console.NewConsole(false).Start("Cask Installs")
158162
for _, app := range installer.ToInstall {
159163
i := Cask{
160-
App: app,
164+
App: app,
165+
Console: c,
161166
}
162167
if err := Install(i); err != nil {
163168
return fmt.Errorf("cask install: %w", err)
164169
}
165170
}
171+
c.End("Cask Installs")
166172
case "apm":
173+
c := console.NewConsole(false).Start("APM Installs")
167174
for _, app := range installer.ToInstall {
168175
i := APM{
169176
Package: app,
177+
Console: c,
170178
}
171179
if err := Install(i); err != nil {
172180
return fmt.Errorf("APM install: %w", err)
173181
}
174182
}
183+
c.End("APN Installs")
175184
case "mas":
185+
c := console.NewConsole(false).Start("MAS Installs")
176186
for _, app := range installer.ToInstall {
177187
i := MAS{
178-
App: app,
188+
App: app,
189+
Console: c,
179190
}
180191
if err := Install(i); err != nil {
181192
return fmt.Errorf("MAS install: %w", err)
182193
}
183194
}
195+
c.End("MAS Installs")
184196
}
185197
}
186198
}

apps/runners.go

+44-5
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,32 @@ package apps
33
import (
44
"fmt"
55
"os/exec"
6+
7+
"github.com/Keloran/dotfilesLoader/console"
68
)
79

810
type Runner interface {
911
install() error
1012
}
1113

1214
type Brew struct {
13-
App string
15+
App string
16+
Console console.Console
1417
}
1518

1619
type Cask struct {
17-
App string
20+
App string
21+
Console console.Console
1822
}
1923

2024
type MAS struct {
21-
App string
25+
App string
26+
Console console.Console
2227
}
2328

2429
type APM struct {
2530
Package string
31+
Console console.Console
2632
}
2733

2834
func Install(r Runner) error {
@@ -36,22 +42,55 @@ func (i Brew) install() error {
3642
}
3743

3844
if len(out) > 0 {
39-
fmt.Printf("%s\n", out)
45+
i.Console.Log(fmt.Sprintf("%s output: %s\n", i.App, out))
4046
} else {
41-
fmt.Printf("%s installed\n", i.App)
47+
i.Console.Info(fmt.Sprintf("%s installed\n", i.App))
4248
}
4349

4450
return nil
4551
}
4652

4753
func (i Cask) install() error {
54+
out, err := exec.Command("brew", "cask", "install", i.App).Output()
55+
if err != nil {
56+
return fmt.Errorf("runners casks: %w", err)
57+
}
58+
59+
if len(out) > 0 {
60+
i.Console.Log(fmt.Sprintf("%s output: %s\n", i.App, out))
61+
} else {
62+
i.Console.Info(fmt.Sprintf("%s installed\n", i.App))
63+
}
64+
4865
return nil
4966
}
5067

5168
func (i MAS) install() error {
69+
out, err := exec.Command("mas", "install", i.App).Output()
70+
if err != nil {
71+
return fmt.Errorf("runners mas: %w", err)
72+
}
73+
74+
if len(out) > 0 {
75+
i.Console.Log(fmt.Sprintf("%s output: %s\n", i.App, out))
76+
} else {
77+
i.Console.Info(fmt.Sprintf("%s installed\n", i.App))
78+
}
79+
5280
return nil
5381
}
5482

5583
func (i APM) install() error {
84+
out, err := exec.Command("apm", "install", i.Package).Output()
85+
if err != nil {
86+
return fmt.Errorf("runners mas: %w", err)
87+
}
88+
89+
if len(out) > 0 {
90+
i.Console.Log(fmt.Sprintf("%s output: %s\n", i.Package, out))
91+
} else {
92+
i.Console.Info(fmt.Sprintf("%s installed\n", i.Package))
93+
}
94+
5695
return nil
5796
}

0 commit comments

Comments
 (0)