aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn / boringcactus <melody@boringcactus.com>2021-06-13 20:48:15 -0600
committerMelody Horn / boringcactus <melody@boringcactus.com>2021-06-13 20:48:15 -0600
commitd30b5db6f3eabd2a550ef05e6203d3c7ef19e9c7 (patch)
tree073f2781edb4b08841ea7cf6098371e2d994d7c8 /src
parent75e5e5f857b50a0eedbde84bcb10035479fc4571 (diff)
downloadtosin-d30b5db6f3eabd2a550ef05e6203d3c7ef19e9c7.tar.gz
tosin-d30b5db6f3eabd2a550ef05e6203d3c7ef19e9c7.zip
pass the first halfish of tutorial 1 tests
Diffstat (limited to 'src')
-rw-r--r--src/bin/tosin-admin.rs58
-rw-r--r--src/urls.rs10
2 files changed, 63 insertions, 5 deletions
diff --git a/src/bin/tosin-admin.rs b/src/bin/tosin-admin.rs
index a1f03fb..3eb57a1 100644
--- a/src/bin/tosin-admin.rs
+++ b/src/bin/tosin-admin.rs
@@ -1,5 +1,31 @@
+use std::env::set_current_dir;
+use std::fs;
+use std::io::Write as _;
+use std::process::Command;
+
use structopt::StructOpt;
+const TOSIN_DEPENDENCY: &str = concat!(r#"tosin = { path = ""#, env!("CARGO_MANIFEST_DIR"), r#"" }"#);
+const PROJECT_MAIN: &str = r#"
+use tosin::Settings;
+use tosin::contrib::admin;
+use tosin::urls::{UrlMap, url_map};
+
+fn urls() -> UrlMap {
+ url_map! {
+ "admin" / ..admin::site::urls(),
+ }
+}
+
+fn settings() -> Settings {
+ Settings {
+ ..Settings::default()
+ }
+}
+
+tosin::main!(urls(), settings());
+"#;
+
#[derive(StructOpt, Debug)]
enum Opt {
/// Start a new project/site (can contain multiple apps)
@@ -10,5 +36,35 @@ enum Opt {
fn main() {
let opts = Opt::from_args();
- dbg!(opts);
+ match opts {
+ Opt::StartProject { name } => {
+ match name {
+ Some(name) => {
+ // there's a name, so we're creating a project.
+ // TODO make this all more robust
+ let cargo_new = Command::new("cargo")
+ .args(&["new", "--bin", &name])
+ .status()
+ .unwrap();
+ if !cargo_new.success() {
+ panic!("cargo new failed");
+ }
+
+ set_current_dir(name).unwrap();
+
+ let mut cargo_toml = fs::OpenOptions::new()
+ .append(true)
+ .open("Cargo.toml")
+ .unwrap();
+ writeln!(cargo_toml, "{}", TOSIN_DEPENDENCY).unwrap();
+ drop(cargo_toml);
+
+ fs::write("src/main.rs", PROJECT_MAIN).unwrap();
+ }
+ None => {
+ todo!("absorb existing Rust project maybe??")
+ }
+ }
+ }
+ }
}
diff --git a/src/urls.rs b/src/urls.rs
index 80eba9e..2668835 100644
--- a/src/urls.rs
+++ b/src/urls.rs
@@ -1,6 +1,8 @@
use crate::http::Response;
pub use crate::url_map;
+pub use warp::path as warp_path;
+
pub type UrlMap = warp::filters::BoxedFilter<(Response,)>;
#[doc(hidden)]
@@ -40,20 +42,20 @@ macro_rules! __url_map_inner {
($chain:ident @rest) => { $chain };
(@one => $view:expr) => {
- ::warp::path::end().map($view)
+ $crate::urls::warp_path::end().map($view)
};
(@one $head:tt $(/ $tail:tt)* => $view:expr) => {
- ::warp::path!($head $(/ $tail)*).map($view)
+ $crate::urls::warp_path!($head $(/ $tail)*).map($view)
};
(@one $head:tt $(/ $tail:tt)* $child:expr) => {
- ::warp::path!($head $(/ $tail)*).and($child)
+ $crate::urls::warp_path!($head $(/ $tail)*).and($child)
};
}
#[macro_export]
macro_rules! url_map {
($($body:tt)*) => {{
- use ::warp::Filter;
+ use $crate::http::Filter;
$crate::__url_map_inner!(@root $($body)*)
.boxed()
}};