@@ -3,9 +3,7 @@ package cmd
33import (
44 "errors"
55 "fmt"
6- "log"
76 "os"
8- "strings"
97
108 "github.com/fatih/color"
119 "github.com/spf13/afero"
@@ -24,43 +22,33 @@ func (cli *CLI) init(opts Options) int {
2422 return ExitCodeError
2523 }
2624
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
3426 for _ , wd := range workingDirs {
35- builder .Reset ()
3627 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-
4328 cfg , err := tflint .LoadConfig (afero.Afero {Fs : afero .NewOsFs ()}, opts .Config )
4429 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+ }
4735 }
4836
49- found := false
5037 for _ , pluginCfg := range cfg .Plugins {
5138 installCfg := plugin .NewInstallConfig (cfg , pluginCfg )
5239
5340 // If version or source is not set, you need to install it manually
5441 if installCfg .ManuallyInstalled () {
5542 continue
5643 }
57- found = true
5844
5945 _ , err := plugin .FindPluginPath (installCfg )
6046 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+ }
6452
6553 _ , err = installCfg .Install ()
6654 if err != nil {
@@ -71,34 +59,17 @@ func (cli *CLI) init(opts Options) int {
7159 }
7260 }
7361
74- any_installed = true
7562 installed = true
7663 fmt .Fprintf (cli .outStream , "Installed \" %s\" (source: %s, version: %s)\n " , pluginCfg .Name , pluginCfg .Source , pluginCfg .Version )
7764 }
7865
7966 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+ }
8272 }
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 )
10273 }
10374
10475 return nil
@@ -108,7 +79,7 @@ func (cli *CLI) init(opts Options) int {
10879 return ExitCodeError
10980 }
11081 }
111- if opts . Recursive && ! any_installed {
82+ if ! installed {
11283 fmt .Fprint (cli .outStream , "All plugins are already installed\n " )
11384 }
11485
0 commit comments