From 0f761b81654018dae2c2dbcfd2d94b886a0f319c Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Mon, 16 Oct 2023 14:04:46 -0400 Subject: [PATCH] Rename deployment -> deployments + use positional args --- README.md | 20 +++++++++++++++-- src/command.rs | 8 +++---- .../create.graphql | 0 .../{deployment => deployments}/create.rs | 22 ++++++------------- .../describe.graphql | 0 .../{deployment => deployments}/describe.rs | 4 +--- .../{deployment => deployments}/list.graphql | 0 .../{deployment => deployments}/list.rs | 2 +- .../{deployment => deployments}/logs.graphql | 0 .../{deployment => deployments}/logs.rs | 9 +++----- .../{deployment => deployments}/mod.rs | 12 +++++----- .../services/katana.rs | 0 .../services/madara.rs | 0 .../services/mod.rs | 0 .../services/torii.rs | 0 15 files changed, 40 insertions(+), 37 deletions(-) rename src/command/{deployment => deployments}/create.graphql (100%) rename src/command/{deployment => deployments}/create.rs (89%) rename src/command/{deployment => deployments}/describe.graphql (100%) rename src/command/{deployment => deployments}/describe.rs (95%) rename src/command/{deployment => deployments}/list.graphql (100%) rename src/command/{deployment => deployments}/list.rs (97%) rename src/command/{deployment => deployments}/logs.graphql (100%) rename src/command/{deployment => deployments}/logs.rs (86%) rename src/command/{deployment => deployments}/mod.rs (69%) rename src/command/{deployment => deployments}/services/katana.rs (100%) rename src/command/{deployment => deployments}/services/madara.rs (100%) rename src/command/{deployment => deployments}/services/mod.rs (100%) rename src/command/{deployment => deployments}/services/torii.rs (100%) diff --git a/README.md b/README.md index 2af1237..998ef9f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,23 @@ Authenticate with Cartridge slot auth login ``` -Create a Katana deployment +Create service deployments ``` -slot deployment create -n katana +slot deployments create katana +slot deployments create torii --world 0x3fa481f41522b90b3684ecfab7650c259a76387fab9c380b7a959e3d4ac69f +``` + +Read service logs +``` +slot deployments logs +``` + +List all deployments +``` +slot deployments list +``` + +View deployments configuration +``` +slot deployments describe ``` \ No newline at end of file diff --git a/src/command.rs b/src/command.rs index 6bba2b0..99a20ee 100644 --- a/src/command.rs +++ b/src/command.rs @@ -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 { @@ -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, } } } diff --git a/src/command/deployment/create.graphql b/src/command/deployments/create.graphql similarity index 100% rename from src/command/deployment/create.graphql rename to src/command/deployments/create.graphql diff --git a/src/command/deployment/create.rs b/src/command/deployments/create.rs similarity index 89% rename from src/command/deployment/create.rs rename to src/command/deployments/create.rs index 62097ad..cdba836 100644 --- a/src/command/deployment/create.rs +++ b/src/command/deployments/create.rs @@ -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, @@ -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; @@ -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, @@ -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), diff --git a/src/command/deployment/describe.graphql b/src/command/deployments/describe.graphql similarity index 100% rename from src/command/deployment/describe.graphql rename to src/command/deployments/describe.graphql diff --git a/src/command/deployment/describe.rs b/src/command/deployments/describe.rs similarity index 95% rename from src/command/deployment/describe.rs rename to src/command/deployments/describe.rs index 06b73ef..35276b3 100644 --- a/src/command/deployment/describe.rs +++ b/src/command/deployments/describe.rs @@ -19,7 +19,7 @@ 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; @@ -27,11 +27,9 @@ 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, } diff --git a/src/command/deployment/list.graphql b/src/command/deployments/list.graphql similarity index 100% rename from src/command/deployment/list.graphql rename to src/command/deployments/list.graphql diff --git a/src/command/deployment/list.rs b/src/command/deployments/list.rs similarity index 97% rename from src/command/deployment/list.rs rename to src/command/deployments/list.rs index 7558021..d785516 100644 --- a/src/command/deployment/list.rs +++ b/src/command/deployments/list.rs @@ -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; diff --git a/src/command/deployment/logs.graphql b/src/command/deployments/logs.graphql similarity index 100% rename from src/command/deployment/logs.graphql rename to src/command/deployments/logs.graphql diff --git a/src/command/deployment/logs.rs b/src/command/deployments/logs.rs similarity index 86% rename from src/command/deployment/logs.rs rename to src/command/deployments/logs.rs index 22b62f4..d407ea5 100644 --- a/src/command/deployment/logs.rs +++ b/src/command/deployments/logs.rs @@ -9,7 +9,7 @@ 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; @@ -17,11 +17,9 @@ 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, @@ -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 { diff --git a/src/command/deployment/mod.rs b/src/command/deployments/mod.rs similarity index 69% rename from src/command/deployment/mod.rs rename to src/command/deployments/mod.rs index 1f8fbd5..67f0200 100644 --- a/src/command/deployment/mod.rs +++ b/src/command/deployments/mod.rs @@ -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.")] @@ -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, } } } diff --git a/src/command/deployment/services/katana.rs b/src/command/deployments/services/katana.rs similarity index 100% rename from src/command/deployment/services/katana.rs rename to src/command/deployments/services/katana.rs diff --git a/src/command/deployment/services/madara.rs b/src/command/deployments/services/madara.rs similarity index 100% rename from src/command/deployment/services/madara.rs rename to src/command/deployments/services/madara.rs diff --git a/src/command/deployment/services/mod.rs b/src/command/deployments/services/mod.rs similarity index 100% rename from src/command/deployment/services/mod.rs rename to src/command/deployments/services/mod.rs diff --git a/src/command/deployment/services/torii.rs b/src/command/deployments/services/torii.rs similarity index 100% rename from src/command/deployment/services/torii.rs rename to src/command/deployments/services/torii.rs