@@ -4,9 +4,13 @@ import (
44 cfg "codacy/cli-v2/config"
55 config_file "codacy/cli-v2/config-file"
66 "fmt"
7+ "io"
78 "log"
9+ "os"
10+ "time"
811
912 "github.com/fatih/color"
13+ "github.com/schollz/progressbar/v3"
1014 "github.com/spf13/cobra"
1115)
1216
@@ -22,8 +26,8 @@ var installCmd = &cobra.Command{
2226 Short : "Installs the tools specified in the project's config-file." ,
2327 Long : "Installs all runtimes and tools specified in the project's config-file file." ,
2428 Run : func (cmd * cobra.Command , args []string ) {
25- cyan := color .New (color .FgCyan )
2629 bold := color .New (color .Bold )
30+ green := color .New (color .FgGreen )
2731
2832 // Initialize config
2933 cfg .Init ()
@@ -37,12 +41,80 @@ var installCmd = &cobra.Command{
3741 bold .Println ("🚀 Starting installation process..." )
3842 fmt .Println ()
3943
40- cyan .Println ("Installing runtimes..." )
41- installRuntimes (& cfg .Config )
44+ // Print list of items to install
45+ fmt .Println ("📦 Items to install:" )
46+ for name , runtime := range cfg .Config .Runtimes () {
47+ fmt .Printf (" • Runtime: %s v%s\n " , name , runtime .Version )
48+ }
49+ for name , tool := range cfg .Config .Tools () {
50+ fmt .Printf (" • Tool: %s v%s\n " , name , tool .Version )
51+ }
52+ fmt .Println ()
53+
54+ // Calculate total items to install
55+ totalItems := len (cfg .Config .Runtimes ()) + len (cfg .Config .Tools ())
4256
43- cyan .Println ("\n Installing tools..." )
44- installTools (& cfg .Config )
57+ // Create a single progress bar for the entire installation
58+ progressBar := progressbar .NewOptions (totalItems ,
59+ progressbar .OptionSetDescription ("Installing components..." ),
60+ progressbar .OptionSetTheme (progressbar.Theme {
61+ Saucer : "█" ,
62+ SaucerHead : "█" ,
63+ SaucerPadding : "░" ,
64+ BarStart : "│" ,
65+ BarEnd : "│" ,
66+ }),
67+ progressbar .OptionShowCount (),
68+ progressbar .OptionShowIts (),
69+ progressbar .OptionSetWidth (50 ),
70+ progressbar .OptionThrottle (100 * time .Millisecond ),
71+ progressbar .OptionSpinnerType (14 ),
72+ progressbar .OptionFullWidth (),
73+ progressbar .OptionSetRenderBlankState (true ),
74+ progressbar .OptionOnCompletion (func () {
75+ fmt .Println ()
76+ }),
77+ )
78+
79+ // Redirect all output to /dev/null during installation
80+ oldStdout := os .Stdout
81+ devNull , _ := os .Open (os .DevNull )
82+ os .Stdout = devNull
83+ log .SetOutput (io .Discard )
84+
85+ // Install runtimes
86+ for name , runtime := range cfg .Config .Runtimes () {
87+ progressBar .Describe (fmt .Sprintf ("Installing runtime: %s v%s..." , name , runtime .Version ))
88+ err := cfg .InstallRuntime (name , runtime )
89+ if err != nil {
90+ log .Fatal (err )
91+ }
92+ progressBar .Add (1 )
93+ }
4594
95+ // Install tools
96+ for name , tool := range cfg .Config .Tools () {
97+ progressBar .Describe (fmt .Sprintf ("Installing tool: %s v%s..." , name , tool .Version ))
98+ err := cfg .InstallTool (name , tool )
99+ if err != nil {
100+ log .Fatal (err )
101+ }
102+ progressBar .Add (1 )
103+ }
104+
105+ // Restore output
106+ os .Stdout = oldStdout
107+ devNull .Close ()
108+ log .SetOutput (os .Stderr )
109+
110+ // Print completion status
111+ fmt .Println ()
112+ for name , runtime := range cfg .Config .Runtimes () {
113+ green .Printf (" ✓ Runtime: %s v%s\n " , name , runtime .Version )
114+ }
115+ for name , tool := range cfg .Config .Tools () {
116+ green .Printf (" ✓ Tool: %s v%s\n " , name , tool .Version )
117+ }
46118 fmt .Println ()
47119 bold .Println ("✅ Installation completed successfully!" )
48120 },
0 commit comments