Skip to content

Commit 8724a50

Browse files
refactor: streamline installation process and enhance user feedback
- Removed configuration file check from main function, allowing direct command execution. - Improved installation command to include detailed logging for tool installation progress. - Added user-friendly messages during the installation process to indicate success and failures.
1 parent 89c81c3 commit 8724a50

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

cli-v2.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,9 @@ package main
22

33
import (
44
"codacy/cli-v2/cmd"
5-
"codacy/cli-v2/config"
6-
cfg "codacy/cli-v2/config-file"
7-
"fmt"
8-
"os"
95
)
106

117
func main() {
12-
configErr := cfg.ReadConfigFile(config.Config.ProjectConfigFile())
13-
// whenever there is no configuration file, the only command allowed to run is the 'init'
14-
if configErr != nil && len(os.Args) > 1 && os.Args[1] != "init" {
15-
fmt.Println("No configuration file was found, execute init command first.")
16-
return
17-
}
188

199
cmd.Execute()
2010
}

cmd/install.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package cmd
22

33
import (
44
cfg "codacy/cli-v2/config"
5+
config_file "codacy/cli-v2/config-file"
6+
"fmt"
57
"log"
68

9+
"github.com/fatih/color"
710
"github.com/spf13/cobra"
811
)
912

@@ -19,8 +22,29 @@ var installCmd = &cobra.Command{
1922
Short: "Installs the tools specified in the project's config-file.",
2023
Long: "Installs all runtimes and tools specified in the project's config-file file.",
2124
Run: func(cmd *cobra.Command, args []string) {
25+
cyan := color.New(color.FgCyan)
26+
bold := color.New(color.Bold)
27+
28+
// Initialize config
29+
cfg.Init()
30+
31+
// Load config file
32+
if err := config_file.ReadConfigFile(cfg.Config.ProjectConfigFile()); err != nil {
33+
log.Fatalf("Failed to load config file: %v", err)
34+
}
35+
36+
fmt.Println()
37+
bold.Println("🚀 Starting installation process...")
38+
fmt.Println()
39+
40+
cyan.Println("Installing runtimes...")
2241
installRuntimes(&cfg.Config)
42+
43+
cyan.Println("\nInstalling tools...")
2344
installTools(&cfg.Config)
45+
46+
fmt.Println()
47+
bold.Println("✅ Installation completed successfully!")
2448
},
2549
}
2650

@@ -37,4 +61,4 @@ func installTools(config *cfg.ConfigType) {
3761
if err != nil {
3862
log.Fatal(err)
3963
}
40-
}
64+
}

config/tools-installer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import (
1616
// InstallTools installs all tools defined in the configuration
1717
func InstallTools() error {
1818
for name, toolInfo := range Config.Tools() {
19+
fmt.Printf("Installing tool: %s v%s...\n", name, toolInfo.Version)
1920
err := InstallTool(name, toolInfo)
2021
if err != nil {
2122
return fmt.Errorf("failed to install tool %s: %w", name, err)
2223
}
24+
fmt.Printf("Successfully installed %s v%s\n", name, toolInfo.Version)
2325
}
2426
return nil
2527
}
@@ -41,15 +43,18 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo) error {
4143
// Check if this is a download-based tool (like trivy) or a runtime-based tool (like eslint)
4244
if toolInfo.DownloadURL != "" {
4345
// This is a download-based tool
46+
fmt.Printf("Downloading %s...\n", name)
4447
return installDownloadBasedTool(toolInfo)
4548
}
4649

4750
// Handle Python tools differently
4851
if toolInfo.Runtime == "python" {
52+
fmt.Printf("Installing Python tool %s...\n", name)
4953
return installPythonTool(name, toolInfo)
5054
}
5155

52-
// Handle other runtime-based tools
56+
// For runtime-based tools
57+
fmt.Printf("Installing %s using %s runtime...\n", name, toolInfo.Runtime)
5358
return installRuntimeTool(name, toolInfo)
5459
}
5560

0 commit comments

Comments
 (0)