Skip to content

Commit

Permalink
chore: replace structopt with clap in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Jul 27, 2024
1 parent 6651d2d commit 6b297e4
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 139 deletions.
120 changes: 11 additions & 109 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion examples/mysql/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ workspace = "../../../"
anyhow = "1.0"
futures = "0.3"
sqlx = { path = "../../../", features = [ "mysql", "runtime-tokio-native-tls" ] }
structopt = "0.3"
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
10 changes: 5 additions & 5 deletions examples/mysql/todos/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use clap::{Parser, Subcommand};
use sqlx::mysql::MySqlPool;
use std::env;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(subcommand)]
#[command(subcommand)]
cmd: Option<Command>,
}

#[derive(StructOpt)]
#[derive(Subcommand)]
enum Command {
Add { description: String },
Done { id: u64 },
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let args = Args::from_args_safe()?;
let args = Args::parse();
let pool = MySqlPool::connect(&env::var("DATABASE_URL")?).await?;

match args.cmd {
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ futures = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlx = { path = "../../../", features = ["runtime-tokio", "postgres", "json"] }
structopt = "0.3"
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
10 changes: 5 additions & 5 deletions examples/postgres/json/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use clap::{Parser, Subcommand};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use sqlx::postgres::PgPool;
use sqlx::types::Json;
use std::io::{self, Read};
use std::num::NonZeroU8;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(subcommand)]
#[clap(subcommand)]
cmd: Option<Command>,
}

#[derive(StructOpt)]
#[derive(Subcommand)]
enum Command {
Add,
}
Expand All @@ -32,7 +32,7 @@ struct Row {

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let args = Args::from_args_safe()?;
let args = Args::parse();
let pool = PgPool::connect(&dotenvy::var("DATABASE_URL")?).await?;

match args.cmd {
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/mockable-todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ workspace = "../../../"
anyhow = "1.0"
futures = "0.3"
sqlx = { path = "../../../", features = ["postgres", "runtime-tokio-native-tls"] }
structopt = "0.3"
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
dotenvy = "0.15.0"
async-trait = "0.1.41"
Expand Down
10 changes: 5 additions & 5 deletions examples/postgres/mockable-todos/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use async_trait::async_trait;
use clap::{Parser, Subcommand};
use sqlx::postgres::PgPool;
use std::{env, io::Write, sync::Arc};
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(subcommand)]
#[command(subcommand)]
cmd: Option<Command>,
}

#[derive(StructOpt)]
#[derive(Subcommand)]
enum Command {
Add { description: String },
Done { id: i64 },
Expand All @@ -18,7 +18,7 @@ enum Command {
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
let args = Args::from_args_safe()?;
let args = Args::parse();
let pool = PgPool::connect(&env::var("DATABASE_URL")?).await?;
let todo_repo = PostgresTodoRepo::new(pool);
let mut writer = std::io::stdout();
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ workspace = "../../../"
anyhow = "1.0"
futures = "0.3"
sqlx = { path = "../../../", features = ["postgres", "runtime-tokio-native-tls"] }
structopt = "0.3"
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
dotenvy = "0.15.0"
Loading

0 comments on commit 6b297e4

Please sign in to comment.