Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cargo-shuttle): new template system for init #1667

Merged
merged 9 commits into from Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 11 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Expand Up @@ -47,8 +47,9 @@ bollard = "0.15.0"
bytes = "1.3.0"
cargo_metadata = "0.18.1"
chrono = { version = "0.4.23", default-features = false }
colored = "2.0.0"
clap = { version = "4.2.7", features = ["derive"] }
colored = "2.0.0"
comfy-table = "6.2.0"
crossterm = "0.27.0"
ctor = "0.2.5"
dirs = "5.0.0"
Expand All @@ -59,6 +60,7 @@ futures = "0.3.27"
headers = "0.3.8"
home = "0.5.4"
http = "0.2.8"
http-body = "0.4.5"
hyper = "0.14.23"
# not great, but waiting for WebSocket changes to be merged
hyper-reverse-proxy = { git = "https://github.com/chesedo/hyper-reverse-proxy", branch = "bug/host_header" }
Expand Down Expand Up @@ -86,7 +88,7 @@ serde = { version = "1.0.148", default-features = false }
serde_json = "1.0.89"
sqlx = { version = "0.7.1", features = ["runtime-tokio", "tls-rustls"] }
strfmt = "0.2.2"
strum = { version = "0.25.0", features = ["derive"] }
strum = { version = "0.26.1", features = ["derive"] }
tar = "0.4.38"
tempfile = "3.4.0"
test-context = "0.3.0"
Expand All @@ -108,5 +110,5 @@ ttl_cache = "0.5.1"
ulid = "1.0.0"
url = "2.4.0"
uuid = "1.2.2"
wiremock = "0.6.0-rc.3"
wiremock = "0.6.0"
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved
zeroize = "1.6.0"
2 changes: 1 addition & 1 deletion cargo-shuttle/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ clap = { workspace = true, features = ["env"] }
clap_complete = "4.3.1"
clap_mangen = "0.2.15"
crossterm = { workspace = true }
dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }
dialoguer = { version = "0.11", default-features = false, features = ["password"] }
dirs = { workspace = true }
dunce = { workspace = true }
flate2 = { workspace = true }
Expand Down
46 changes: 24 additions & 22 deletions cargo-shuttle/src/args.rs
Expand Up @@ -12,7 +12,7 @@ use clap::{
Parser, ValueEnum,
};
use clap_complete::Shell;
use shuttle_common::constants::DEFAULT_IDLE_MINUTES;
use shuttle_common::constants::{DEFAULT_IDLE_MINUTES, EXAMPLES_REPO};
use shuttle_common::resource;
use uuid::Uuid;

Expand All @@ -33,6 +33,10 @@ pub struct ShuttleArgs {
/// (allows targeting a custom deployed instance for this command only, mainly for development)
#[arg(long, env = "SHUTTLE_API")]
pub api_url: Option<String>,
/// Disable network requests that are not strictly necessary. Limits some features.
#[arg(long, env = "SHUTTLE_OFFLINE")]
pub offline: bool,

#[command(subcommand)]
pub cmd: Command,
}
Expand Down Expand Up @@ -320,43 +324,41 @@ pub struct InitArgs {
/// Don't initialize a new git repository
#[arg(long)]
pub no_git: bool,

#[command(flatten)]
pub login_args: LoginArgs,
}

#[derive(ValueEnum, Clone, Debug, strum::Display, strum::EnumIter)]
#[strum(serialize_all = "kebab-case")]
#[derive(ValueEnum, Clone, Debug, strum::EnumMessage, strum::VariantArray)]
pub enum InitTemplateArg {
/// Actix Web framework
ActixWeb,
/// Axum web framework
/// Axum - Modular web framework from the Tokio ecosystem
Axum,
/// Loco web framework
/// Actix Web - Powerful and fast web framework
ActixWeb,
/// Rocket - Simple and easy-to-use web framework
Rocket,
/// Loco - Batteries included web framework based on Axum
Loco,
/// Poem web framework
/// Salvo - Powerful and simple web framework
Salvo,
/// Poem - Full-featured and easy-to-use web framework
Poem,
/// Poise Discord framework
/// Poise - Discord Bot framework with good slash command support
Poise,
/// Rocket web framework
Rocket,
/// Salvo web framework
Salvo,
/// Serenity Discord framework
/// Serenity - Discord Bot framework
Serenity,
/// Thruster web framework
/// Tower - Modular service library
Tower,
/// Thruster - Web framework
Thruster,
/// Tide web framework
/// Tide - Web framework
Tide,
/// Tower web framework
Tower,
/// Warp web framework
/// Warp - Web framework
Warp,
/// No template - Custom empty service
/// No template - Make a custom service
None,
}

pub const EXAMPLES_REPO: &str = "https://github.com/shuttle-hq/shuttle-examples";

#[derive(Clone, Debug, PartialEq)]
pub struct TemplateLocation {
pub auto_path: String,
Expand Down
8 changes: 4 additions & 4 deletions cargo-shuttle/src/init.rs
Expand Up @@ -12,7 +12,7 @@ use gix::create::{self, Kind};
use gix::remote::fetch::Shallow;
use gix::{open, progress};
use regex::Regex;
use shuttle_common::constants::SHUTTLE_EXAMPLES_README;
use shuttle_common::constants::EXAMPLES_README;
use tempfile::{Builder, TempDir};
use toml_edit::{value, Document};
use url::Url;
Expand Down Expand Up @@ -101,8 +101,8 @@ fn setup_template(auto_path: &str) -> Result<TempDir> {
// `owner` and `name` are required for the regex to
// match. Thus, we don't need to check if they exist.
let url = format!("{vendor}{}/{}.git", &caps["owner"], &caps["name"]);
gix_clone(&url, temp_dir.path())
.with_context(|| format!("Failed to clone template Git repository at {url}"))?;
println!(r#"Cloning from "{}"..."#, url);
gix_clone(&url, temp_dir.path()).context("Failed to clone git repository")?;
} else if Path::new(auto_path).is_absolute() || auto_path.starts_with('.') {
if Path::new(auto_path).exists() {
copy_dirs(Path::new(auto_path), temp_dir.path(), GitDir::Copy)?;
Expand All @@ -121,7 +121,7 @@ fn setup_template(auto_path: &str) -> Result<TempDir> {
or use another method of specifying the template location."
);
println!(
"HINT: You can find examples of how to select a template here: {SHUTTLE_EXAMPLES_README}"
"HINT: You can find examples of how to select a template here: {EXAMPLES_README}"
);
anyhow::bail!("invalid URL scheme")
}
Expand Down