diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7cd0e8..ebb044d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,3 +41,60 @@ jobs: - name: Run Docker Image run: docker run --network host sqlant postgresql://user:password@localhost/db + + test-library-no-clap: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Create test project using sqlant as library + run: | + # Create a temporary test project + mkdir -p /tmp/test-sqlant-lib + cd /tmp/test-sqlant-lib + + # Initialize a new Rust project + cargo init --lib + + # Add sqlant as a library dependency (using local path) + cat > Cargo.toml << 'EOF' + [package] + name = "test-sqlant-lib" + version = "0.1.0" + edition = "2021" + + [dependencies] + sqlant = { path = "${{ github.workspace }}", default-features = false } + EOF + + # Create a simple lib.rs that uses sqlant + cat > src/lib.rs << 'EOF' + use sqlant::GeneratorType; + + pub fn test_use_sqlant() { + let _ = GeneratorType::PlantUML; + } + EOF + + - name: Build test project + run: | + cd /tmp/test-sqlant-lib + cargo build + + - name: Verify clap is not in Cargo.lock + run: | + cd /tmp/test-sqlant-lib + if grep -q "name = \"clap\"" Cargo.lock; then + echo "ERROR: clap found in Cargo.lock when using sqlant as library" + echo "sqlant should not depend on clap when used as a library" + exit 1 + else + echo "SUCCESS: clap is not in Cargo.lock" + fi diff --git a/Cargo.toml b/Cargo.toml index 69e4d6a..a9d92cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ tinytemplate = "1.2" serde = { version = "1.0", features = ["derive"] } strum = "0.26" strum_macros = "0.26" -clap = "4.1.4" +clap = { version = "4", optional = true } tokio-postgres = "0.7" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } postgres-native-tls = "0.5.0" @@ -28,6 +28,12 @@ opt-level = "z" # Optimize for size. strip = true lto = true +[[bin]] +name = "sqlant" +path = "src/main.rs" +required-features = ["cli"] + [features] -default = ["vendored-tls"] +default = ["vendored-tls", "cli"] vendored-tls = ["native-tls/vendored"] +cli = ["dep:clap"] diff --git a/src/lib.rs b/src/lib.rs index 35466c4..06f2ec4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ use strum_macros::{Display, EnumString}; -pub mod cli; pub mod error; pub mod mermaid_generator; pub mod plantuml_generator; diff --git a/src/main.rs b/src/main.rs index 1ce6216..88ec50e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,13 +3,15 @@ use std::str::FromStr; use clap::ArgMatches; use sqlant::{get_generator, lookup_parser, GeneratorConfigOptions, GeneratorType}; +mod cli; + fn get_arg(args: &ArgMatches, arg_name: &str) -> String { args.get_one::(arg_name).unwrap().to_string() } #[tokio::main] async fn main() { - let args = sqlant::cli::parse(); + let args = cli::parse(); let mut s = lookup_parser( &get_arg(&args, "connection_string"),