///|
/// The platform of the process, for the system and user configuration
/// directories.
async fn platform(store : &@provider.DocumentStore) -> @config.Platform {
  if @env.get_env_var("WINDIR") is Some(_) {
    return Windows
  }
  let mac = try {
    store.list(@okf.StoreDir("System/Library")) |> ignore
    true
  } catch {
    _ => false
  }
  if mac {
    MacOs
  } else {
    Linux
  }
}

///|
/// The shell: build the host from the process, run the command, write its
/// lines and exit with its code.
async fn main {
  let root = @provider.StoreRoot("/") catch { _ => panic() }
  let store : &@provider.DocumentStore = @okf_fs.FsStore(root)
  let host : @command.Host = {
    store,
    working_dir: @env.current_dir().unwrap_or("/"),
    env_vars: @env.get_env_vars(),
    platform: Some(platform(store)),
    read_stdin: async fn() { @stdio.stdin.read_all().text() catch { _ => "" } },
    clock: @okf.FixedClock(
      @okf.Instant::of_millis(@env.now().reinterpret_as_int64()),
    ),
  }
  let outcome = @command.execute(program_args(), host)
  for line in outcome.lines {
    match line {
      Stdout(text) => println(text)
      Stderr(text) => eprintln(text)
    }
  }
  let code = outcome.exit.to_int()
  if code != 0 {
    @env.exit(code)
  }
}