| 72 | } |
| 73 | |
| 74 | func (f *File) Configure(inlineArgs []string, cfg *config.Map) error { |
| 75 | switch len(inlineArgs) { |
| 76 | case 1: |
| 77 | f.file = inlineArgs[0] |
| 78 | case 0: |
| 79 | default: |
| 80 | return fmt.Errorf("%s: cannot use multiple files with single %s, use %s multiple times to do so", FileModName, FileModName, FileModName) |
| 81 | } |
| 82 | |
| 83 | var file string |
| 84 | cfg.Bool("debug", true, false, &f.log.Debug) |
| 85 | cfg.String("file", false, false, "", &file) |
| 86 | if _, err := cfg.Process(); err != nil { |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | if file != "" { |
| 91 | if f.file != "" { |
| 92 | return fmt.Errorf("%s: file path specified both in directive and in argument, do it once", FileModName) |
| 93 | } |
| 94 | f.file = file |
| 95 | } |
| 96 | |
| 97 | if err := readFile(f.file, f.m); err != nil { |
| 98 | if !os.IsNotExist(err) { |
| 99 | return err |
| 100 | } |
| 101 | f.log.Printf("ignoring non-existent file: %s", f.file) |
| 102 | } |
| 103 | |
| 104 | return nil |
| 105 | } |
| 106 | |
| 107 | func (f *File) Start() error { |
| 108 | go f.reloader() |