aboutsummaryrefslogtreecommitdiff
path: root/src/bin
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/bin
parent75e5e5f857b50a0eedbde84bcb10035479fc4571 (diff)
downloadtosin-d30b5db6f3eabd2a550ef05e6203d3c7ef19e9c7.tar.gz
tosin-d30b5db6f3eabd2a550ef05e6203d3c7ef19e9c7.zip
pass the first halfish of tutorial 1 tests
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/tosin-admin.rs58
1 files changed, 57 insertions, 1 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??")
+ }
+ }
+ }
+ }
}