@@ -3,9 +3,7 @@ package cmd
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "log"
7
6
"os"
8
- "strings"
9
7
10
8
"github.com/fatih/color"
11
9
"github.com/spf13/afero"
@@ -24,43 +22,33 @@ func (cli *CLI) init(opts Options) int {
24
22
return ExitCodeError
25
23
}
26
24
27
- var builder strings.Builder
28
-
29
- if opts .Recursive {
30
- fmt .Fprint (cli .outStream , "Installing plugins on each working directory...\n \n " )
31
- }
32
-
33
- any_installed := false
25
+ installed := false
34
26
for _ , wd := range workingDirs {
35
- builder .Reset ()
36
27
err := cli .withinChangedDir (wd , func () error {
37
- installed := false
38
- if opts .Recursive {
39
- builder .WriteString ("====================================================\n " )
40
- builder .WriteString (fmt .Sprintf ("working directory: %s\n \n " , wd ))
41
- }
42
-
43
28
cfg , err := tflint .LoadConfig (afero.Afero {Fs : afero .NewOsFs ()}, opts .Config )
44
29
if err != nil {
45
- fmt .Fprint (cli .outStream , builder .String ())
46
- return fmt .Errorf ("Failed to load TFLint config; %w" , err )
30
+ if opts .Recursive {
31
+ return fmt .Errorf ("Failed to load TFLint config in %s; %w" , wd , err )
32
+ } else {
33
+ return fmt .Errorf ("Failed to load TFLint config; %w" , err )
34
+ }
47
35
}
48
36
49
- found := false
50
37
for _ , pluginCfg := range cfg .Plugins {
51
38
installCfg := plugin .NewInstallConfig (cfg , pluginCfg )
52
39
53
40
// If version or source is not set, you need to install it manually
54
41
if installCfg .ManuallyInstalled () {
55
42
continue
56
43
}
57
- found = true
58
44
59
45
_ , err := plugin .FindPluginPath (installCfg )
60
46
if os .IsNotExist (err ) {
61
- fmt .Fprint (cli .outStream , builder .String ())
62
- builder .Reset ()
63
- fmt .Fprintf (cli .outStream , "Installing \" %s\" plugin...\n " , pluginCfg .Name )
47
+ if opts .Recursive {
48
+ fmt .Fprintf (cli .outStream , "Installing \" %s\" plugin in %s...\n " , pluginCfg .Name , wd )
49
+ } else {
50
+ fmt .Fprintf (cli .outStream , "Installing \" %s\" plugin...\n " , pluginCfg .Name )
51
+ }
64
52
65
53
_ , err = installCfg .Install ()
66
54
if err != nil {
@@ -71,34 +59,17 @@ func (cli *CLI) init(opts Options) int {
71
59
}
72
60
}
73
61
74
- any_installed = true
75
62
installed = true
76
63
fmt .Fprintf (cli .outStream , "Installed \" %s\" (source: %s, version: %s)\n " , pluginCfg .Name , pluginCfg .Source , pluginCfg .Version )
77
64
}
78
65
79
66
if err != nil {
80
- fmt .Fprint (cli .outStream , builder .String ())
81
- return fmt .Errorf ("Failed to find a plugin; %w" , err )
67
+ if opts .Recursive {
68
+ return fmt .Errorf ("Failed to find a plugin in %s; %w" , wd , err )
69
+ } else {
70
+ return fmt .Errorf ("Failed to find a plugin; %w" , err )
71
+ }
82
72
}
83
-
84
- builder .WriteString (fmt .Sprintf ("Plugin \" %s\" is already installed\n " , pluginCfg .Name ))
85
- }
86
-
87
- if opts .Recursive && ! found {
88
- builder .WriteString ("No plugins to install\n " )
89
- }
90
-
91
- if installed || ! opts .Recursive {
92
- fmt .Fprint (cli .outStream , builder .String ())
93
- return nil
94
- }
95
-
96
- // If there are no changes, send logs to debug
97
- prefix := "[DEBUG] "
98
- lines := strings .Split (builder .String (), "\n " )
99
-
100
- for _ , line := range lines {
101
- log .Printf ("%s%s" , prefix , line )
102
73
}
103
74
104
75
return nil
@@ -108,7 +79,7 @@ func (cli *CLI) init(opts Options) int {
108
79
return ExitCodeError
109
80
}
110
81
}
111
- if opts . Recursive && ! any_installed {
82
+ if ! installed {
112
83
fmt .Fprint (cli .outStream , "All plugins are already installed\n " )
113
84
}
114
85
0 commit comments