Skip to content

Commit

Permalink
Rename deployment -> deployments + use positional args
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Oct 16, 2023
1 parent c83dd2b commit 0f761b8
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 37 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ Authenticate with Cartridge
slot auth login
```

Create a Katana deployment
Create service deployments
```
slot deployment create -n <Project Name> katana
slot deployments create <Project Name> katana
slot deployments create <Project Name> torii --world 0x3fa481f41522b90b3684ecfab7650c259a76387fab9c380b7a959e3d4ac69f
```

Read service logs
```
slot deployments logs <Project Name> <katana | torii>
```

List all deployments
```
slot deployments list
```

View deployments configuration
```
slot deployments describe <Project Name> <katana | torii>
```
8 changes: 4 additions & 4 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pub mod auth;
pub mod deployment;
pub mod deployments;

use anyhow::Result;
use clap::Subcommand;

use auth::Auth;
use deployment::Deployment;
use deployments::Deployments;

#[derive(Subcommand, Debug)]
pub enum Command {
Expand All @@ -14,14 +14,14 @@ pub enum Command {
Auth(Auth),
#[command(subcommand)]
#[command(about = "Manage Slot deployments.")]
Deployment(Deployment),
Deployments(Deployments),
}

impl Command {
pub async fn run(&self) -> Result<()> {
match &self {
Command::Auth(cmd) => cmd.run().await,
Command::Deployment(cmd) => cmd.run().await,
Command::Deployments(cmd) => cmd.run().await,
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use graphql_client::{GraphQLQuery, Response};
use self::create_deployment::ServiceInput;
use crate::{
api::ApiClient,
command::deployment::create::create_deployment::{
command::deployments::create::create_deployment::{
CreateDeploymentCreateDeployment::{KatanaConfig, ToriiConfig},
DeploymentService, DeploymentTier, KatanaConfigInput, ServiceConfigInput, ToriiConfigInput,
Variables,
Expand All @@ -21,7 +21,7 @@ type Long = u64;
#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployment/create.graphql",
query_path = "src/command/deployments/create.graphql",
response_derives = "Debug"
)]
pub struct CreateDeployment;
Expand All @@ -31,23 +31,15 @@ pub enum Tier {
Basic,
}

#[derive(Debug, Args, serde::Serialize)]
#[command(next_help_heading = "Create deployment options")]
pub struct CreateOptions {
#[arg(short, long = "project")]
#[derive(Debug, Args)]
#[command(next_help_heading = "Create options")]
pub struct CreateArgs {
#[arg(help = "The name of the project.")]
pub project: String,
#[arg(short, long, default_value = "basic")]
#[arg(value_name = "tier")]
#[arg(help = "Deployment tier.")]
pub tier: Tier,
}

#[derive(Debug, Args)]
#[command(next_help_heading = "Create options")]
pub struct CreateArgs {
#[command(flatten)]
options: CreateOptions,

#[command(subcommand)]
create_commands: CreateCommands,
Expand Down Expand Up @@ -87,12 +79,12 @@ impl CreateArgs {
},
};

let tier = match &self.options.tier {
let tier = match &self.tier {
Tier::Basic => DeploymentTier::basic,
};

let request_body = CreateDeployment::build_query(Variables {
project: self.options.project.clone(),
project: self.project.clone(),
tier,
service,
wait: Some(true),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ type Long = u64;
#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployment/describe.graphql",
query_path = "src/command/deployments/describe.graphql",
response_derives = "Debug"
)]
pub struct DescribeDeployment;

#[derive(Debug, Args)]
#[command(next_help_heading = "Describe options")]
pub struct DescribeArgs {
#[arg(short, long = "project")]
#[arg(help = "The project of the project.")]
pub project: String,

#[arg(short, long = "service")]
#[arg(help = "The service of the project.")]
pub service: Service,
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use self::list_deployments::{ResponseData, Variables};
#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployment/list.graphql",
query_path = "src/command/deployments/list.graphql",
response_derives = "Debug"
)]
pub struct ListDeployments;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ use super::services::Service;
#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployment/logs.graphql",
query_path = "src/command/deployments/logs.graphql",
response_derives = "Debug"
)]
pub struct DeploymentLogs;

#[derive(Debug, Args)]
#[command(next_help_heading = "Deployment logs options")]
pub struct LogsArgs {
#[arg(short, long = "project")]
#[arg(help = "The project of the deployment.")]
pub project: String,

#[arg(short, long = "service")]
#[arg(help = "The name of the deployment service.")]
pub service: Service,

Expand Down Expand Up @@ -55,10 +53,9 @@ impl LogsArgs {
let entries = res
.data
.and_then(|data| data.deployment)
.and_then(|deployment| Some(deployment.logs.entries))
.unwrap_or_default();
.map(|deployment| deployment.logs.entries);

for e in entries.iter() {
for e in entries.unwrap().iter() {
if e.trim() == "{}" {
println!("\n");
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/command/deployment/mod.rs → src/command/deployments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod logs;
mod services;

#[derive(Subcommand, Debug)]
pub enum Deployment {
pub enum Deployments {
#[command(about = "Create a new deployment.")]
Create(CreateArgs),
#[command(about = "Describe a deployment's configuration.")]
Expand All @@ -21,13 +21,13 @@ pub enum Deployment {
Logs(LogsArgs),
}

impl Deployment {
impl Deployments {
pub async fn run(&self) -> Result<()> {
match &self {
Deployment::Create(args) => args.run().await,
Deployment::Describe(args) => args.run().await,
Deployment::List(args) => args.run().await,
Deployment::Logs(args) => args.run().await,
Deployments::Create(args) => args.run().await,
Deployments::Describe(args) => args.run().await,
Deployments::List(args) => args.run().await,
Deployments::Logs(args) => args.run().await,
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0f761b8

Please sign in to comment.