rebrand project to workspace
This commit is contained in:
parent
0d03a0fbc2
commit
31b439ee31
8 changed files with 26 additions and 26 deletions
|
@ -4,7 +4,7 @@ Tools for developping planetwars bots locally.
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
1. Initialize your project directory: `pwcli init-project my_project`
|
1. Initialize your workspace directory: `pwcli init my_workspace`
|
||||||
2. Enter your fresh project: `cd my_project`
|
2. Enter your fresh workspace: `cd my_workspace`
|
||||||
3. Run an example match: `pwcli run-match hex simplebot simplebot`
|
3. Run an example match: `pwcli run-match hex simplebot simplebot`
|
||||||
4. View your match in the web UI: `pwcli serve`
|
4. View your match in the web UI: `pwcli serve`
|
||||||
|
|
|
@ -5,7 +5,7 @@ use futures::io;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct InitCommand {
|
pub struct InitCommand {
|
||||||
/// project root directory
|
/// workspace root directory
|
||||||
path: String,
|
path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ impl InitCommand {
|
||||||
std::fs::create_dir_all(path.join("bots/simplebot"))?;
|
std::fs::create_dir_all(path.join("bots/simplebot"))?;
|
||||||
|
|
||||||
// create files
|
// 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("maps"), "hex.json");
|
||||||
copy_asset!(path.join("bots/simplebot"), "simplebot.py");
|
copy_asset!(path.join("bots/simplebot"), "simplebot.py");
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl Cli {
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Initialize a new project
|
/// Initialize a new workspace
|
||||||
Init(init::InitCommand),
|
Init(init::InitCommand),
|
||||||
/// Run a match
|
/// Run a match
|
||||||
RunMatch(run_match::RunMatchCommand),
|
RunMatch(run_match::RunMatchCommand),
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::match_runner;
|
||||||
use crate::match_runner::MatchBot;
|
use crate::match_runner::MatchBot;
|
||||||
use crate::match_runner::MatchConfig;
|
use crate::match_runner::MatchConfig;
|
||||||
use crate::resolve_bot_config;
|
use crate::resolve_bot_config;
|
||||||
use crate::ProjectConfig;
|
use crate::WorkspaceConfig;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct RunMatchCommand {
|
pub struct RunMatchCommand {
|
||||||
|
@ -19,24 +19,24 @@ pub struct RunMatchCommand {
|
||||||
|
|
||||||
impl RunMatchCommand {
|
impl RunMatchCommand {
|
||||||
pub async fn run(self) -> io::Result<()> {
|
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 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 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
|
let players = self
|
||||||
.bots
|
.bots
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|bot_name| {
|
.map(|bot_name| {
|
||||||
let bot_config = project_config.bots.get(&bot_name).unwrap().clone();
|
let bot_config = workspace_config.bots.get(&bot_name).unwrap().clone();
|
||||||
let resolved_config = resolve_bot_config(&project_dir, bot_config);
|
let resolved_config = resolve_bot_config(&workspace_root, bot_config);
|
||||||
MatchBot {
|
MatchBot {
|
||||||
name: bot_name,
|
name: bot_name,
|
||||||
bot_config: resolved_config,
|
bot_config: resolved_config,
|
||||||
|
@ -54,7 +54,7 @@ impl RunMatchCommand {
|
||||||
match_runner::run_match(match_config).await;
|
match_runner::run_match(match_config).await;
|
||||||
println!("match completed successfully");
|
println!("match completed successfully");
|
||||||
// TODO: don't hardcode match path.
|
// 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);
|
println!("wrote match log to matches/{}.log", timestamp);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ pub struct ServeCommand;
|
||||||
|
|
||||||
impl ServeCommand {
|
impl ServeCommand {
|
||||||
pub async fn run(self) -> io::Result<()> {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct ProjectConfig {
|
struct WorkspaceConfig {
|
||||||
bots: HashMap<String, BotConfig>,
|
bots: HashMap<String, BotConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ pub async fn run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_bot_config(project_dir: &Path, config: BotConfig) -> BotConfig {
|
fn resolve_bot_config(workspace_dir: &Path, config: BotConfig) -> BotConfig {
|
||||||
let mut path = PathBuf::from(project_dir);
|
let mut path = PathBuf::from(workspace_dir);
|
||||||
path.push(&config.path);
|
path.push(&config.path);
|
||||||
BotConfig {
|
BotConfig {
|
||||||
path: path.to_str().unwrap().to_string(),
|
path: path.to_str().unwrap().to_string(),
|
||||||
|
|
|
@ -21,17 +21,17 @@ use std::{
|
||||||
use crate::match_runner::MatchMeta;
|
use crate::match_runner::MatchMeta;
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
project_root: PathBuf,
|
workspace_root: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
fn new(project_root: PathBuf) -> Self {
|
fn new(workspace_root: PathBuf) -> Self {
|
||||||
Self { project_root }
|
Self { workspace_root }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(project_root: PathBuf) {
|
pub async fn run(workspace_root: PathBuf) {
|
||||||
let shared_state = Arc::new(State::new(project_root));
|
let shared_state = Arc::new(State::new(workspace_root));
|
||||||
|
|
||||||
// build our application with a route
|
// build our application with a route
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
|
@ -59,7 +59,7 @@ struct MatchData {
|
||||||
|
|
||||||
async fn list_matches(Extension(state): Extension<Arc<State>>) -> Json<Vec<MatchData>> {
|
async fn list_matches(Extension(state): Extension<Arc<State>>) -> Json<Vec<MatchData>> {
|
||||||
let matches = state
|
let matches = state
|
||||||
.project_root
|
.workspace_root
|
||||||
.join("matches")
|
.join("matches")
|
||||||
.read_dir()
|
.read_dir()
|
||||||
.unwrap()
|
.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 {
|
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");
|
match_path.set_extension("log");
|
||||||
fs::read_to_string(match_path).unwrap()
|
fs::read_to_string(match_path).unwrap()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue