Skip to content

Commit

Permalink
feat(cargo-shuttle): v0.48.2, colored platform outputs, fixes (#1886)
Browse files Browse the repository at this point in the history
* feat: colored platform outputs

* chore: unhide beta commands

* nits

* fix: beta deprecate clean command

* fix(cargo-shuttle): don't validate api key, beta login url

* fix: mentions of cargo shuttle

* chore: bump cargo-shuttle

* fix: show project id when deleting

* tracing log
  • Loading branch information
jonaro00 authored Oct 10, 2024
1 parent d01466e commit be7b731
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/BUG-REPORT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ body:
id: version
attributes:
label: Version
description: What version of `cargo-shuttle` are you running (`cargo shuttle --version`)?
description: What version of `cargo-shuttle` are you running (`shuttle --version`)?
placeholder: "v0.48.0"
validations:
required: true
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,20 @@ iwr "https://www.shuttle.rs/install-win" | iex
After installing, log in with:

```sh
cargo shuttle login
shuttle login
```

To initialize your project, simply write:

```bash
cargo shuttle init --template axum hello-world
shuttle init --template axum hello-world
```

And to deploy it, write:

```bash
cd hello-world
cargo shuttle project start # Only needed if project has not already been created during init
cargo shuttle deploy --allow-dirty
shuttle deploy
```

And... that's it!
Expand Down Expand Up @@ -163,7 +162,7 @@ async fn main() -> shuttle_axum::ShuttleAxum {
}
```

Now, with just `cargo shuttle deploy`, you can see your application live. But let's enhance it further by adding a shared Postgres database:
Now, with just `shuttle deploy`, you can see your application live. But let's enhance it further by adding a shared Postgres database:

```rust
use axum::{routing::get, Router};
Expand All @@ -187,7 +186,7 @@ async fn main(
}
```

Now, if we run `cargo shuttle deploy`, we'll have an up and running project with a database inside & ready to use.
Now, if we run `shuttle deploy`, we'll have an up and running project with a database inside & ready to use.
<br>
<br>

Expand Down
2 changes: 1 addition & 1 deletion cargo-shuttle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-shuttle"
version = "0.48.1"
version = "0.48.2"
edition.workspace = true
license.workspace = true
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion cargo-shuttle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cargo install cargo-shuttle

## Documentation

Run `cargo shuttle help` to see the basic usage.
Run `shuttle help` to see the basic usage.

Full list of commands and more documentation can be viewed on the [CLI docs](https://docs.shuttle.rs/getting-started/shuttle-commands).

Expand Down
48 changes: 23 additions & 25 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use shuttle_common::resource;
pub struct ShuttleArgs {
#[command(flatten)]
pub project_args: ProjectArgs,
/// Run this command against the API at the supplied URL
/// (allows targeting a custom deployed instance for this command only, mainly for development)
/// URL for the Shuttle API to target (mainly for development)
#[arg(global = true, long, env = "SHUTTLE_API")]
pub api_url: Option<String>,
/// Disable network requests that are not strictly necessary. Limits some features.
Expand All @@ -46,7 +45,7 @@ pub struct ShuttleArgs {
pub cmd: Command,
}

// Common args for subcommands that deal with projects.
/// Global args for subcommands that deal with projects
#[derive(Parser, Clone, Debug)]
pub struct ProjectArgs {
/// Specify the working directory
Expand Down Expand Up @@ -102,34 +101,34 @@ impl ProjectArgs {
pub enum Command {
/// Generate a Shuttle project from a template
Init(InitArgs),
/// Run a Shuttle service locally
/// Run a project locally
Run(RunArgs),
/// Deploy a Shuttle service
/// Deploy a project
Deploy(DeployArgs),
/// Manage deployments of a Shuttle service
/// Manage deployments
#[command(subcommand, visible_alias = "depl")]
Deployment(DeploymentCommand),
/// View the status of a Shuttle service
Status,
/// Stop a Shuttle service
Stop,
/// View logs of a Shuttle service
/// View build and deployment logs
Logs(LogsArgs),
/// Manage projects on Shuttle
/// Manage Shuttle projects
#[command(subcommand, visible_alias = "proj")]
Project(ProjectCommand),
/// Manage resources
#[command(subcommand, visible_alias = "res")]
Resource(ResourceCommand),
/// BETA: Manage SSL certificates for custom domains
#[command(subcommand, visible_alias = "cert", hide = true)]
/// Manage SSL certificates for custom domains
#[command(subcommand, visible_alias = "cert")]
Certificate(CertificateCommand),
/// Remove cargo build artifacts in the Shuttle environment
Clean,
/// BETA: Show info about your Shuttle account
#[command(visible_alias = "acc", hide = true)]
/// Show info about your Shuttle account
#[command(visible_alias = "acc")]
Account,
/// Login to the Shuttle platform
/// Log in to the Shuttle platform
Login(LoginArgs),
/// Log out of the Shuttle platform
Logout(LogoutArgs),
Expand Down Expand Up @@ -162,8 +161,8 @@ pub enum GenerateCommand {

#[derive(Parser)]
pub struct TableArgs {
#[arg(long, default_value_t = false)]
/// Output tables without borders
#[arg(long, default_value_t = false)]
pub raw: bool,
}

Expand All @@ -172,12 +171,12 @@ pub enum DeploymentCommand {
/// List the deployments for a service
#[command(visible_alias = "ls")]
List {
#[arg(long, default_value = "1")]
/// Which page to display
#[arg(long, default_value = "1")]
page: u32,

#[arg(long, default_value = "10", visible_alias = "per-page")]
/// How many deployments per page to display
#[arg(long, default_value = "10", visible_alias = "per-page")]
limit: u32,

#[command(flatten)]
Expand All @@ -188,8 +187,7 @@ pub enum DeploymentCommand {
/// ID of deployment to get status for
id: Option<String>,
},
/// BETA: Stop running deployment(s)
#[command(hide = true)]
/// Stop running deployment(s)
Stop,
}

Expand All @@ -201,8 +199,8 @@ pub enum ResourceCommand {
#[command(flatten)]
table: TableArgs,

#[arg(long, default_value_t = false)]
/// Show secrets from resources (e.g. a password in a connection string)
#[arg(long, default_value_t = false)]
show_secrets: bool,
},
/// Delete a resource
Expand Down Expand Up @@ -247,9 +245,9 @@ pub enum ProjectCommand {
Start(ProjectStartArgs),
/// Check the status of this project's environment on Shuttle
Status {
#[arg(short, long)]
/// Follow status of project
// unused in beta (project has no state to follow)
#[arg(short, long)]
follow: bool,
},
/// Destroy this project's environment (container) on Shuttle
Expand Down Expand Up @@ -277,8 +275,8 @@ pub enum ProjectCommand {

#[derive(Parser, Debug)]
pub struct ConfirmationArgs {
#[arg(long, short, default_value_t = false)]
/// Skip confirmations and proceed
#[arg(long, short, default_value_t = false)]
pub yes: bool,
}

Expand Down Expand Up @@ -306,11 +304,11 @@ pub struct LogoutArgs {

#[derive(Parser, Default)]
pub struct DeployArgs {
/// BETA: Deploy this Docker image instead of building one
/// WIP: Deploy this Docker image instead of building one
#[arg(long, short = 'i', hide = true)]
pub image: Option<String>, // TODO?: Make this a subcommand instead? `cargo shuttle deploy image ...`
/// BETA: Don't follow the deployment status, exit after the deployment begins
#[arg(long, visible_alias = "nf", hide = true)]
pub image: Option<String>, // TODO?: Make this a subcommand instead? `shuttle deploy image ...`
/// Don't follow the deployment status, exit after the deployment begins
#[arg(long, visible_alias = "nf")]
pub no_follow: bool,

/// Allow deployment with uncommitted files
Expand Down
29 changes: 13 additions & 16 deletions cargo-shuttle/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use anyhow::{anyhow, Context, Result};
use serde::{Deserialize, Serialize};
use shuttle_common::constants::API_URL_BETA;
use shuttle_common::{constants::API_URL_DEFAULT, ApiKey};
use shuttle_common::constants::API_URL_DEFAULT;
use tracing::trace;

use crate::args::ProjectArgs;
Expand Down Expand Up @@ -128,12 +128,12 @@ pub struct GlobalConfig {
}

impl GlobalConfig {
pub fn api_key(&self) -> Option<Result<ApiKey>> {
self.api_key.as_ref().map(|key| ApiKey::parse(key))
pub fn api_key(&self) -> Option<String> {
self.api_key.clone()
}

pub fn set_api_key(&mut self, api_key: ApiKey) -> Option<String> {
self.api_key.replace(api_key.as_ref().to_string())
pub fn set_api_key(&mut self, api_key: String) -> Option<String> {
self.api_key.replace(api_key)
}

pub fn clear_api_key(&mut self) {
Expand Down Expand Up @@ -432,22 +432,19 @@ impl RequestContext {
/// Get the API key from the `SHUTTLE_API_KEY` env variable, or
/// otherwise from the global configuration. Returns an error if
/// an API key is not set.
pub fn api_key(&self) -> Result<ApiKey> {
let api_key = std::env::var("SHUTTLE_API_KEY");

if let Ok(key) = api_key {
ApiKey::parse(&key).context("environment variable SHUTTLE_API_KEY is invalid")
} else {
match self.global.as_ref().unwrap().api_key() {
Some(key) => key,
pub fn api_key(&self) -> Result<String> {
match std::env::var("SHUTTLE_API_KEY") {
Ok(key) => Ok(key),
Err(_) => match self.global.as_ref().unwrap().api_key() {
Some(key) => Ok(key),
None => Err(anyhow!(
"Configuration file: `{}`",
self.global.manager.path().display()
)
.context(anyhow!(
"No valid API key found, try logging in first with:\n\tcargo shuttle login"
"No valid API key found, try logging in first with `shuttle login`"
))),
}
},
}
}

Expand All @@ -465,7 +462,7 @@ impl RequestContext {
}

/// Set the API key to the global configuration. Will persist the file.
pub fn set_api_key(&mut self, api_key: ApiKey) -> Result<()> {
pub fn set_api_key(&mut self, api_key: String) -> Result<()> {
self.global.as_mut().unwrap().set_api_key(api_key);
self.global.save()
}
Expand Down
Loading

0 comments on commit be7b731

Please sign in to comment.