rebrand project to workspace

This commit is contained in:
Ilion Beyst 2021-12-26 22:00:20 +01:00
parent 0d03a0fbc2
commit 31b439ee31
8 changed files with 26 additions and 26 deletions

View file

@ -4,7 +4,7 @@ Tools for developping planetwars bots locally.
## Getting started
1. Initialize your project directory: `pwcli init-project my_project`
2. Enter your fresh project: `cd my_project`
1. Initialize your workspace directory: `pwcli init my_workspace`
2. Enter your fresh workspace: `cd my_workspace`
3. Run an example match: `pwcli run-match hex simplebot simplebot`
4. View your match in the web UI: `pwcli serve`

View file

@ -5,7 +5,7 @@ use futures::io;
#[derive(Parser)]
pub struct InitCommand {
/// project root directory
/// workspace root directory
path: String,
}
@ -29,7 +29,7 @@ impl InitCommand {
std::fs::create_dir_all(path.join("bots/simplebot"))?;
// create files
copy_asset!(path, "pw_project.toml");
copy_asset!(path, "pw_workspace.toml");
copy_asset!(path.join("maps"), "hex.json");
copy_asset!(path.join("bots/simplebot"), "simplebot.py");

View file

@ -27,7 +27,7 @@ impl Cli {
#[derive(Subcommand)]
enum Command {
/// Initialize a new project
/// Initialize a new workspace
Init(init::InitCommand),
/// Run a match
RunMatch(run_match::RunMatchCommand),

View file

@ -7,7 +7,7 @@ use crate::match_runner;
use crate::match_runner::MatchBot;
use crate::match_runner::MatchConfig;
use crate::resolve_bot_config;
use crate::ProjectConfig;
use crate::WorkspaceConfig;
#[derive(Parser)]
pub struct RunMatchCommand {
@ -19,24 +19,24 @@ pub struct RunMatchCommand {
impl RunMatchCommand {
pub async fn run(self) -> io::Result<()> {
let project_dir = env::current_dir().unwrap();
let workspace_root = env::current_dir().unwrap();
let config_path = project_dir.join("pw_project.toml");
let config_path = workspace_root.join("pw_workspace.toml");
let map_path = project_dir.join(format!("maps/{}.json", self.map));
let map_path = workspace_root.join(format!("maps/{}.json", self.map));
let timestamp = chrono::Local::now().format("%Y-%m-%d-%H-%M-%S");
let log_path = project_dir.join(format!("matches/{}.log", timestamp));
let log_path = workspace_root.join(format!("matches/{}.log", timestamp));
let config_str = std::fs::read_to_string(config_path).unwrap();
let project_config: ProjectConfig = toml::from_str(&config_str).unwrap();
let workspace_config: WorkspaceConfig = toml::from_str(&config_str).unwrap();
let players = self
.bots
.into_iter()
.map(|bot_name| {
let bot_config = project_config.bots.get(&bot_name).unwrap().clone();
let resolved_config = resolve_bot_config(&project_dir, bot_config);
let bot_config = workspace_config.bots.get(&bot_name).unwrap().clone();
let resolved_config = resolve_bot_config(&workspace_root, bot_config);
MatchBot {
name: bot_name,
bot_config: resolved_config,
@ -54,7 +54,7 @@ impl RunMatchCommand {
match_runner::run_match(match_config).await;
println!("match completed successfully");
// TODO: don't hardcode match path.
// maybe print the match result as well?
// maybe print the match result as well?
println!("wrote match log to matches/{}.log", timestamp);
Ok(())
}

View file

@ -10,9 +10,9 @@ pub struct ServeCommand;
impl ServeCommand {
pub async fn run(self) -> io::Result<()> {
let project_dir = env::current_dir().unwrap();
let workspace_root = env::current_dir().unwrap();
web::run(project_dir).await;
web::run(workspace_root).await;
Ok(())
}
}

View file

@ -9,7 +9,7 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};
#[derive(Serialize, Deserialize, Debug)]
struct ProjectConfig {
struct WorkspaceConfig {
bots: HashMap<String, BotConfig>,
}
@ -27,8 +27,8 @@ pub async fn run() {
}
}
fn resolve_bot_config(project_dir: &Path, config: BotConfig) -> BotConfig {
let mut path = PathBuf::from(project_dir);
fn resolve_bot_config(workspace_dir: &Path, config: BotConfig) -> BotConfig {
let mut path = PathBuf::from(workspace_dir);
path.push(&config.path);
BotConfig {
path: path.to_str().unwrap().to_string(),

View file

@ -21,17 +21,17 @@ use std::{
use crate::match_runner::MatchMeta;
struct State {
project_root: PathBuf,
workspace_root: PathBuf,
}
impl State {
fn new(project_root: PathBuf) -> Self {
Self { project_root }
fn new(workspace_root: PathBuf) -> Self {
Self { workspace_root }
}
}
pub async fn run(project_root: PathBuf) {
let shared_state = Arc::new(State::new(project_root));
pub async fn run(workspace_root: PathBuf) {
let shared_state = Arc::new(State::new(workspace_root));
// build our application with a route
let app = Router::new()
@ -59,7 +59,7 @@ struct MatchData {
async fn list_matches(Extension(state): Extension<Arc<State>>) -> Json<Vec<MatchData>> {
let matches = state
.project_root
.workspace_root
.join("matches")
.read_dir()
.unwrap()
@ -104,7 +104,7 @@ fn read_match_meta(path: &path::Path) -> io::Result<MatchMeta> {
}
async fn get_match(Extension(state): Extension<Arc<State>>, Path(id): Path<String>) -> String {
let mut match_path = state.project_root.join("matches").join(id);
let mut match_path = state.workspace_root.join("matches").join(id);
match_path.set_extension("log");
fs::read_to_string(match_path).unwrap()
}