|
| 1 | +package status |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/RohitRavindra-dev/devlocal/internal/config" |
| 7 | + "github.com/RohitRavindra-dev/devlocal/internal/filesystem" |
| 8 | + "github.com/RohitRavindra-dev/devlocal/internal/git" |
| 9 | +) |
| 10 | + |
| 11 | +func displayConfigVersion(version int) { |
| 12 | + fmt.Printf("[Version] %d \n", version) |
| 13 | +} |
| 14 | + |
| 15 | +func displayOverlookStatus(fileNames []string) { |
| 16 | + fmt.Println("[Overlooked files]") |
| 17 | + if len(fileNames) == 0 { |
| 18 | + fmt.Println("\t- No files registed in config for overlooking!") |
| 19 | + return |
| 20 | + } |
| 21 | + for _, filename := range fileNames { |
| 22 | + exists, err := filesystem.FileExists(filename) |
| 23 | + overlookStatus := "✗" |
| 24 | + overlookComment := "Being tracked" |
| 25 | + if exists { |
| 26 | + |
| 27 | + if isOverlooked, _ := git.IsSkipWorktree(filename); isOverlooked { |
| 28 | + overlookStatus = "✓" |
| 29 | + overlookComment = "Overlooked" |
| 30 | + } |
| 31 | + |
| 32 | + } else { |
| 33 | + overlookComment = err.Error() |
| 34 | + } |
| 35 | + |
| 36 | + fmt.Printf("\t%s %s \n\t\t- %s\n", overlookStatus, filename, overlookComment) |
| 37 | + |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func displayPatchesStatus(patches []string) { |
| 42 | + fmt.Println("[Patches]") |
| 43 | + if len(patches) == 0 { |
| 44 | + fmt.Println("\t- No patches registed in config for patching!") |
| 45 | + return |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +func displayDevlocalConfig(config *config.DevlocalConfigYaml) error { |
| 50 | + fmt.Println("\n===============================") |
| 51 | + fmt.Println("| devlocal [Status] |") |
| 52 | + fmt.Printf("===============================\n\n") |
| 53 | + displayConfigVersion(config.Version) |
| 54 | + fmt.Println() |
| 55 | + displayOverlookStatus(config.Overlook) |
| 56 | + fmt.Println() |
| 57 | + displayPatchesStatus(config.Patches) |
| 58 | + fmt.Printf("===============================\n\n") |
| 59 | + |
| 60 | + return nil |
| 61 | +} |
| 62 | + |
| 63 | +func Run() error { |
| 64 | + |
| 65 | + //load config |
| 66 | + config, err := filesystem.LoadDevlocalConfig() |
| 67 | + if err != nil { |
| 68 | + return err |
| 69 | + } |
| 70 | + |
| 71 | + if err := displayDevlocalConfig(config); err != nil { |
| 72 | + return err |
| 73 | + } |
| 74 | + |
| 75 | + return nil |
| 76 | +} |
0 commit comments