pub fn otter<'s,S>(&self, xargs: &'s [S])
where &'s S: Into<String>
{
- self.otter_rctx(&default(), xargs)?
+ self.otter_prctx(&default(), xargs)?
}
#[throws(AE)]
- pub fn otter_rctx<'s,S>(&self, rctx: &ResolveContext, xargs: &'s [S])
+ pub fn otter_prctx<'s,S>(&self, prctx: &PathResolveContext, xargs: &'s [S])
where &'s S: Into<String>
{
let ds = self;
let exe = ds.subst("@target@/debug/otter")?;
let specs = self.subst("@src@/specs")?;
let mut args: Vec<String> = vec![];
- args.push("--config" .to_owned()); args.push(rctx.resolve(&CONFIG));
- args.push("--spec-dir".to_owned()); args.push(rctx.resolve(&specs) );
+ args.push("--config" .to_owned()); args.push(prctx.resolve(&CONFIG));
+ args.push("--spec-dir".to_owned()); args.push(prctx.resolve(&specs) );
args.extend(xargs.iter().map(|s| s.into()));
let dbg = format!("running {} {:?}", &exe, &args);
debug!("{}", &dbg);
}
#[throws(AE)]
-pub fn prepare_game(ds: &DirSubst, rctx: &ResolveContext, table: &str)
+pub fn prepare_game(ds: &DirSubst, prctx: &PathResolveContext, table: &str)
-> InstanceName {
let game_spec = ds.game_spec_path()?;
let subst = ds.also(&[
("table", table.to_owned()),
- ("game_spec", rctx.resolve(&game_spec)),
+ ("game_spec", prctx.resolve(&game_spec)),
]);
- ds.otter_rctx(rctx, &subst.ss(
+ ds.otter_prctx(prctx, &subst.ss(
"--account server: \
reset \
--reset-table @specs@/test.table.toml \
spec: GameSpec,
alice: Player,
bob: Player,
- rctx: ResolveContext,
+ prctx: PathResolveContext,
}
impl Ctx {
{
let tmp = &(*self.su_rc).borrow().ds.abstmp.clone();
env::set_current_dir("/").expect("cd /");
- self.rctx = ResolveContext::RelativeTo(tmp.clone());
+ self.prctx = PathResolveContext::RelativeTo(tmp.clone());
f(self).expect("run test");
env::set_current_dir(&tmp).expect("cd back");
- self.rctx = default();
+ self.prctx = default();
}
}
["--account", "server:"].iter().cloned().map(Into::into)
.chain(args.iter().map(|s| s.as_ref().to_owned()))
.collect();
- self.su().ds.otter_rctx(&self.rctx, &args)?;
+ self.su().ds.otter_prctx(&self.prctx, &args)?;
}
#[throws(AE)]
fn library_load(&mut self) {
- prepare_game(&self.su().ds, &self.rctx, TABLE)?;
+ prepare_game(&self.su().ds, &self.prctx, TABLE)?;
let command = self.su().ds.ss(
"library-add @table@ wikimedia chess-blue-?"
drop(mc);
let su_rc = Rc::new(RefCell::new(su));
- tests(Ctx { opts, spec, su_rc, alice, bob, rctx: default() })?;
+ tests(Ctx { opts, spec, su_rc, alice, bob, prctx: default() })?;
}
info!("ok");
}
pub debug_js_inject: Arc<String>,
pub check_bundled_sources: bool,
pub game_rng: RngWrap,
- pub rctx: ResolveContext,
+ pub prctx: PathResolveContext,
}
#[derive(Debug,Copy,Clone)]
-pub enum ResolveMethod {
- ForServerReal,
- Other,
+pub enum PathResolveMethod {
+ Chdir,
+ Prefix,
}
-impl Default for ResolveMethod { fn default() -> Self { Self::Other } }
+impl Default for PathResolveMethod { fn default() -> Self { Self::Prefix } }
#[derive(Debug,Clone)]
-pub enum ResolveContext {
+pub enum PathResolveContext {
RelativeTo(String),
Noop,
}
-impl Default for ResolveContext { fn default() -> Self { Self::Noop } }
+impl Default for PathResolveContext { fn default() -> Self { Self::Noop } }
-impl ResolveMethod {
+impl PathResolveMethod {
#[throws(io::Error)]
- fn chdir(self, cd: &str) -> ResolveContext {
- use ResolveMethod::*;
- use ResolveContext::*;
+ fn chdir(self, cd: &str) -> PathResolveContext {
+ use PathResolveMethod::*;
+ use PathResolveContext::*;
match self {
- ForServerReal => { env::set_current_dir(cd)?; Noop },
- Other if cd == "." => Noop,
- Other => RelativeTo(cd.to_string()),
+ Chdir => { env::set_current_dir(cd)?; Noop },
+ Prefix if cd == "." => Noop,
+ Prefix => RelativeTo(cd.to_string()),
}
}
}
-impl ResolveContext {
+impl PathResolveContext {
pub fn resolve(&self, input: &str) -> String {
- use ResolveContext::*;
+ use PathResolveContext::*;
match (self, input.as_bytes()) {
(Noop , _ ) |
(RelativeTo(_ ), &[b'/',..]) => input.to_owned(),
impl ServerConfigSpec {
//#[throws(AE)]
- pub fn resolve(self, rmeth: ResolveMethod) -> Result<WholeServerConfig,AE> {
+ pub fn resolve(self, prmeth: PathResolveMethod)
+ -> Result<WholeServerConfig,AE> {
let ServerConfigSpec {
change_directory, base_dir, save_dir, command_socket, debug,
http_port, public_url, sse_wildcard_url, rocket_workers,
let game_rng = fake_rng.make_game_rng();
- let rctx;
+ let prctx;
if let Some(ref cd) = change_directory {
- rctx = rmeth.chdir(cd)
+ prctx = prmeth.chdir(cd)
.with_context(|| cd.clone())
.context("config change_directory")?;
} else {
- rctx = ResolveContext::Noop;
+ prctx = PathResolveContext::Noop;
};
let defpath = |specd: Option<String>, leaf: &str| -> String {
- rctx.resolve(&specd.unwrap_or_else(|| match &base_dir {
+ prctx.resolve(&specd.unwrap_or_else(|| match &base_dir {
Some(base) => format!("{}/{}", &base, &leaf),
None => leaf.to_owned(),
}))
vec![ shapelib::Config1::PathGlob(glob) ]
});
- let sendmail = rctx.resolve(&sendmail.unwrap_or_else(
+ let sendmail = prctx.resolve(&sendmail.unwrap_or_else(
|| DEFAULT_SENDMAIL_PROGRAM.into()
));
http_port, public_url, sse_wildcard_url, rocket_workers,
template_dir, nwtemplate_dir, wasm_dir,
bundled_sources, shapelibs, sendmail,
- debug_js_inject, check_bundled_sources, game_rng, rctx,
+ debug_js_inject, check_bundled_sources, game_rng, prctx,
};
trace_dbg!("config resolved", &server);
Ok(WholeServerConfig {
impl ServerConfig {
#[throws(StartupError)]
- pub fn read(config_filename: Option<&str>, rmeth: ResolveMethod) {
+ pub fn read(config_filename: Option<&str>, prmeth: PathResolveMethod) {
let config_filename = config_filename.map(|s| s.to_string())
.unwrap_or_else(
|| format!("{}/{}", DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_LEAFNAME)
File::open(&config_filename).with_context(||config_filename.to_string())?
.read_to_string(&mut buf)?;
let spec: ServerConfigSpec = toml_de::from_str(&buf)?;
- let whole = spec.resolve(rmeth)?;
+ let whole = spec.resolve(prmeth)?;
set_config(whole);
}