@@ -25,38 +25,64 @@ func main() {
2525 c := config.Config {}
2626
2727 if ! * noConfig {
28- includedDirectories = loadConfig (c , includedDirectories , profilePtr )
29- }
28+ if util .FileExists ("inotify-proxy.yaml" ) {
3029
31- // If no argument is defined, the current directory is used
32- if len (includedDirectories ) == 0 {
33- includedDirectories = append (includedDirectories , "." )
34- }
30+ r , err := os .Open ("inotify-proxy.yaml" )
3531
36- color.Style {color .FgCyan , color .OpBold }.Println ("PROFILE: " + * profilePtr )
37- color.Style {color .FgCyan , color .OpBold }.Println ("DIRECTORIES: " + strings .Join (includedDirectories , "," ))
32+ if err != nil {
33+ color .Errorf ("cannot read file: %v\n " , err )
34+ os .Exit (1 )
35+ }
3836
39- watcher .Watch (includedDirectories , * sleepPtr , * profilePtr )
40- }
37+ defer r .Close ()
4138
42- func loadConfig (c config.Config , includedDirectories []string , profilePtr * string ) []string {
43- if util .FileExists ("inotify-proxy.yaml" ) {
44- color .Info .Println ("load config" )
45- c , err := config .ReadFile ("inotify-proxy.yaml" );
39+ c , err = config .Read (r )
4640
47- if err != nil {
48- color .Errorf ("error: Invalid config provided.\n " )
49- os .Exit (1 )
41+ if err != nil {
42+ color .Errorf ("cannot read config: %v\n " , err )
43+ }
44+
45+ if c .OldGlobalProfile != nil {
46+ color .Errorf ("You are using the old configuration format. Please use the new configuration version.\n " )
47+ color .Print ("\n Please refer: https://github.com/cmuench/inotify-proxy/blob/master/README.md#config\n " )
48+ os .Exit (1 )
49+ }
5050 }
51+ }
5152
52- for _ , watch := range c .Watch {
53- includedDirectories = append (includedDirectories , watch .Dir )
53+ if len (includedDirectories ) > 0 {
54+ for _ , includedDirectory := range includedDirectories {
55+ c .Entries = append (c .Entries , config.WatchEntry {
56+ Directory : includedDirectory ,
57+ Extensions : nil ,
58+ Profile : profilePtr ,
59+ })
5460 }
61+ }
5562
56- if c .Profile != "" {
57- * profilePtr = c .Profile
63+ // If no argument is defined, the current directory is used
64+ if len (c .Entries ) == 0 {
65+ c .AddEntry (config.WatchEntry {
66+ Directory : "." ,
67+ Extensions : nil ,
68+ Profile : profilePtr ,
69+ })
70+ }
71+
72+ color.Style {color .FgMagenta , color .OpBold }.Println ("Watching ..." )
73+ color.Style {color .FgWhite }.Println (strings .Repeat ("-" , 80 ))
74+
75+ for _ , e := range c .Entries {
76+ color.Style {color .FgCyan , color .OpBold }.Printf ("Directory: %s\n " , e .Directory )
77+ if * e .Profile != "" {
78+ color.Style {color .FgCyan , color .OpBold }.Printf ("Profile: %s\n " , * e .Profile )
79+ }
80+ if len (e .Extensions ) > 0 {
81+ color.Style {color .FgCyan , color .OpBold }.Printf ("Extensions: %s\n " , e .Extensions )
5882 }
83+
84+ color.Style {color .FgWhite }.Println (strings .Repeat ("-" , 80 ))
5985 }
6086
61- return includedDirectories
87+ watcher . Watch ( c , * sleepPtr )
6288}
0 commit comments