Skip to content

Commit a05238f

Browse files
committed
Refactor cmd_add.go to utilize ui package for consistent output styling
This commit updates the cmd_add.go file to replace direct color formatting functions with calls to the ui package, ensuring consistent styling across the application. Additionally, it removes obsolete color functions from cmd_helpers.go, streamlining the codebase and enhancing maintainability.
1 parent 620e651 commit a05238f

3 files changed

Lines changed: 5 additions & 23 deletions

File tree

sourcecontrol/cmd/sourcecontrol/cmd_add.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/spf13/cobra"
7+
"github.com/utkarsh5026/SourceControl/cmd/ui"
78
"github.com/utkarsh5026/SourceControl/pkg/index"
89
"github.com/utkarsh5026/SourceControl/pkg/store"
910
)
@@ -16,38 +17,33 @@ func newAddCmd() *cobra.Command {
1617
This stages changes for the next commit.`,
1718
Args: cobra.MinimumNArgs(1),
1819
RunE: func(cmd *cobra.Command, args []string) error {
19-
// Find repository
2020
repo, err := findRepository()
2121
if err != nil {
2222
return err
2323
}
2424

25-
// Create index manager
2625
repoRoot := repo.WorkingDirectory()
2726
indexMgr := index.NewManager(repoRoot)
2827
if err := indexMgr.Initialize(); err != nil {
2928
return fmt.Errorf("failed to initialize index: %w", err)
3029
}
3130

32-
// Create object store
3331
objectStore := store.NewFileObjectStore()
3432
objectStore.Initialize(repo.WorkingDirectory())
3533

36-
// Add files
3734
result, err := indexMgr.Add(args, objectStore)
3835
if err != nil {
3936
return fmt.Errorf("failed to add files: %w", err)
4037
}
4138

42-
// Display results
4339
for _, path := range result.Added {
44-
fmt.Printf("%s %s\n", colorGreen("added:"), path)
40+
fmt.Printf("%s %s\n", ui.Green("added:"), path)
4541
}
4642
for _, path := range result.Modified {
47-
fmt.Printf("%s %s\n", colorYellow("modified:"), path)
43+
fmt.Printf("%s %s\n", ui.Yellow("modified:"), path)
4844
}
4945
for _, failure := range result.Failed {
50-
fmt.Printf("%s %s: %s\n", colorRed("failed:"), failure.Path, failure.Reason)
46+
fmt.Printf("%s %s: %s\n", ui.Red("failed:"), failure.Path, failure.Reason)
5147
}
5248

5349
return nil

sourcecontrol/cmd/sourcecontrol/cmd_helpers.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"os"
66
"path/filepath"
77

8-
"github.com/utkarsh5026/SourceControl/cmd/ui"
98
"github.com/utkarsh5026/SourceControl/pkg/refs/branch"
109
"github.com/utkarsh5026/SourceControl/pkg/repository/scpath"
1110
"github.com/utkarsh5026/SourceControl/pkg/repository/sourcerepo"
@@ -64,16 +63,3 @@ func getCurrentBranchName(repo *sourcerepo.SourceRepository) (string, error) {
6463

6564
return branchName, nil
6665
}
67-
68-
// Wrapper functions for backward compatibility - delegate to ui package
69-
func colorGreen(s string) string {
70-
return ui.Green(s)
71-
}
72-
73-
func colorRed(s string) string {
74-
return ui.Red(s)
75-
}
76-
77-
func colorYellow(s string) string {
78-
return ui.Yellow(s)
79-
}

sourcecontrol/cmd/sourcecontrol/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Displays the commit history starting from the current HEAD.`,
8585
}
8686

8787
if len(history) == 0 {
88-
fmt.Println(colorYellow("📝 No commits yet"))
88+
fmt.Println(ui.Yellow("📝 No commits yet"))
8989
return nil
9090
}
9191

0 commit comments

Comments
 (0)