File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,20 +3,14 @@ package cmd
33import (
44 "backup-rsync/backup/internal"
55 "fmt"
6- "log"
76
87 "github.com/spf13/cobra"
9- "gopkg.in/yaml.v3"
108)
119
1210func buildConfigCommand () * cobra.Command {
1311 var configCmd = & cobra.Command {
1412 Use : "config" ,
1513 Short : "Manage configuration" ,
16- Run : func (cmd * cobra.Command , args []string ) {
17- // Implementation for the config command
18- fmt .Println ("Config command executed" )
19- },
2014 }
2115
2216 var showVerb = & cobra.Command {
@@ -26,12 +20,7 @@ func buildConfigCommand() *cobra.Command {
2620 configPath , _ := cmd .Flags ().GetString ("config" )
2721 cfg := internal .LoadResolvedConfig (configPath )
2822
29- out , err := yaml .Marshal (cfg )
30- if err != nil {
31- log .Fatalf ("Failed to marshal resolved configuration: %v" , err )
32- }
33-
34- fmt .Printf ("Resolved Configuration:\n %s\n " , string (out ))
23+ fmt .Printf ("Resolved Configuration:\n %s\n " , cfg )
3524 },
3625 }
3726
Original file line number Diff line number Diff line change 2020 ErrOverlappingPath = errors .New ("overlapping path detected" )
2121)
2222
23+ func (cfg Config ) String () string {
24+ out , _ := yaml .Marshal (cfg )
25+ return string (out )
26+ }
27+
2328func LoadConfig (reader io.Reader ) (Config , error ) {
2429 var cfg Config
2530
Original file line number Diff line number Diff line change @@ -318,3 +318,17 @@ func TestValidatePaths_InvalidPaths(t *testing.T) {
318318 assert .EqualError (t , err , test .errorMessage )
319319 })
320320}
321+
322+ func TestConfigString_ValidConfig (t * testing.T ) {
323+ cfg := internal.Config {
324+ Sources : []internal.Path {},
325+ Targets : []internal.Path {},
326+ Variables : map [string ]string {},
327+ Jobs : []internal.Job {},
328+ }
329+
330+ expectedOutput := "sources: []\n targets: []\n variables: {}\n jobs: []\n "
331+ actualOutput := cfg .String ()
332+
333+ assert .Equal (t , expectedOutput , actualOutput )
334+ }
You can’t perform that action at this time.
0 commit comments