aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/ao_read_config_files.d
blob: 47980dae9d860651f42a38255ce731c5ea5f3af8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/+
  ao_config_files.d
  - read config files
+/
template SiSUconfiguration() {
  private import
    std.exception,
    // std.regex,
    std.stdio,
    std.utf,
    std.conv : to;
  // private import
  //   ao_rgx;       // ao_defaults.d
  // mixin RgxInit;
  // auto rgx = Rgx();
  private
  struct Config {
    private import std.file;
    final private string readInConfigFile() {
      // enforce(
      //   exists(fn_src)!=0,
      //   "file not found"
      // );
      string[] possible_config_path_locations = [
        environment["PWD"] ~ "/.sisu",
        environment["PWD"] ~ "/_sisu",
        environment["HOME"] ~ "/.sisu",
        "/etc/sisu"
      ];
      string conf_sdl = "conf.sdl";
      string config_file_str;
      foreach(pth; possible_config_path_locations) {
        auto conf_file = format(
          "%s/%s",
          pth,
          conf_sdl,
        );
        // writeln(conf_file);
        try {
          if (exists(conf_file)) {
            writeln(conf_file);
            config_file_str = readText(conf_file);
            break;
          }
        }
        catch (ErrnoException ex) {
        //// Handle errors
        // switch(ex.errno) {
        // case EPERM:
        // case EACCES:
        //   // Permission denied
        //   break;
        // case ENOENT:
        //   // File does not exist
        //   break;
        // default:
        //   // Handle other errors
        //   break;
        // }
        }
        // catch (UTFException ex) {
        //   // Handle validation errors
        // }
        catch (FileException ex) {
          // Handle errors
        }
      }
      return config_file_str;
    }
  }
}