Skip to content

Commit 0f76f3c

Browse files
authored
Move cli.rs out of lib.rs (#59)
1 parent a18ce89 commit 0f76f3c

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,60 @@ jobs:
4141

4242
- name: Run Docker Image
4343
run: docker run --network host sqlant postgresql://user:password@localhost/db
44+
45+
test-library-no-clap:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout Repository
49+
uses: actions/checkout@v4
50+
51+
- name: Setup Rust
52+
uses: actions-rs/toolchain@v1
53+
with:
54+
toolchain: stable
55+
override: true
56+
57+
- name: Create test project using sqlant as library
58+
run: |
59+
# Create a temporary test project
60+
mkdir -p /tmp/test-sqlant-lib
61+
cd /tmp/test-sqlant-lib
62+
63+
# Initialize a new Rust project
64+
cargo init --lib
65+
66+
# Add sqlant as a library dependency (using local path)
67+
cat > Cargo.toml << 'EOF'
68+
[package]
69+
name = "test-sqlant-lib"
70+
version = "0.1.0"
71+
edition = "2021"
72+
73+
[dependencies]
74+
sqlant = { path = "${{ github.workspace }}", default-features = false }
75+
EOF
76+
77+
# Create a simple lib.rs that uses sqlant
78+
cat > src/lib.rs << 'EOF'
79+
use sqlant::GeneratorType;
80+
81+
pub fn test_use_sqlant() {
82+
let _ = GeneratorType::PlantUML;
83+
}
84+
EOF
85+
86+
- name: Build test project
87+
run: |
88+
cd /tmp/test-sqlant-lib
89+
cargo build
90+
91+
- name: Verify clap is not in Cargo.lock
92+
run: |
93+
cd /tmp/test-sqlant-lib
94+
if grep -q "name = \"clap\"" Cargo.lock; then
95+
echo "ERROR: clap found in Cargo.lock when using sqlant as library"
96+
echo "sqlant should not depend on clap when used as a library"
97+
exit 1
98+
else
99+
echo "SUCCESS: clap is not in Cargo.lock"
100+
fi

Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tinytemplate = "1.2"
1717
serde = { version = "1.0", features = ["derive"] }
1818
strum = "0.26"
1919
strum_macros = "0.26"
20-
clap = "4.1.4"
20+
clap = { version = "4", optional = true }
2121
tokio-postgres = "0.7"
2222
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
2323
postgres-native-tls = "0.5.0"
@@ -28,6 +28,12 @@ opt-level = "z" # Optimize for size.
2828
strip = true
2929
lto = true
3030

31+
[[bin]]
32+
name = "sqlant"
33+
path = "src/main.rs"
34+
required-features = ["cli"]
35+
3136
[features]
32-
default = ["vendored-tls"]
37+
default = ["vendored-tls", "cli"]
3338
vendored-tls = ["native-tls/vendored"]
39+
cli = ["dep:clap"]

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use strum_macros::{Display, EnumString};
22

3-
pub mod cli;
43
pub mod error;
54
pub mod mermaid_generator;
65
pub mod plantuml_generator;

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ use std::str::FromStr;
33
use clap::ArgMatches;
44
use sqlant::{get_generator, lookup_loader, Direction, GeneratorConfigOptions, GeneratorType};
55

6+
mod cli;
7+
68
fn get_arg(args: &ArgMatches, arg_name: &str) -> String {
79
args.get_one::<String>(arg_name).unwrap().to_string()
810
}
911

1012
#[tokio::main]
1113
async fn main() {
12-
let args = sqlant::cli::parse();
14+
let args = cli::parse();
1315

1416
let mut s = lookup_loader(
1517
&get_arg(&args, "connection_string"),

0 commit comments

Comments
 (0)