mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
Feat: merge gamedig-cli partially & monorepo conversion
Related issue: #125
This commit is contained in:
commit
89222b1f44
71 changed files with 133 additions and 49 deletions
7
.github/labeler.yml
vendored
7
.github/labeler.yml
vendored
|
|
@ -5,10 +5,13 @@ ci:
|
||||||
- .pre-commit-config.yaml
|
- .pre-commit-config.yaml
|
||||||
|
|
||||||
protocol:
|
protocol:
|
||||||
- src/protocols/**
|
- crates/lib/src/protocols/**
|
||||||
|
|
||||||
game:
|
game:
|
||||||
- src/games/**
|
- crates/lib/src/games/**
|
||||||
|
|
||||||
|
cli:
|
||||||
|
- crates/cli/**
|
||||||
|
|
||||||
crate:
|
crate:
|
||||||
- Cargo.toml
|
- Cargo.toml
|
||||||
|
|
|
||||||
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
|
|
@ -31,9 +31,9 @@ jobs:
|
||||||
shared-key: "cargo-deps"
|
shared-key: "cargo-deps"
|
||||||
cache-targets: false
|
cache-targets: false
|
||||||
- name: Run Build
|
- name: Run Build
|
||||||
run: cargo build --verbose --bins --lib --examples --all-features
|
run: cargo check --verbose --workspace --bins --lib --examples --all-features
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: cargo test --verbose --bins --lib --examples --all-features
|
run: cargo test --verbose --workspace --bins --lib --examples --all-features
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [ "build_first" ]
|
needs: [ "build_first" ]
|
||||||
|
|
@ -61,9 +61,9 @@ jobs:
|
||||||
shared-key: "cargo-deps"
|
shared-key: "cargo-deps"
|
||||||
cache-targets: false
|
cache-targets: false
|
||||||
- name: Run Build
|
- name: Run Build
|
||||||
run: cargo build --verbose --bins --lib ${{ matrix.build_type }}
|
run: cargo check --workspace --verbose --bins --lib ${{ matrix.build_type }}
|
||||||
build_msrv:
|
build_msrv:
|
||||||
name: "Build using MSRV"
|
name: "Build using MSRV (lib only)"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
@ -74,7 +74,7 @@ jobs:
|
||||||
toolchain: 1.65.0
|
toolchain: 1.65.0
|
||||||
override: true
|
override: true
|
||||||
- name: Run MSRV
|
- name: Run MSRV
|
||||||
run: cargo build
|
run: cargo check -p gamedig
|
||||||
formatting:
|
formatting:
|
||||||
name: "Check code formatting"
|
name: "Check code formatting"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -105,10 +105,10 @@ jobs:
|
||||||
uses: actions-rs/clippy-check@v1
|
uses: actions-rs/clippy-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
args: --bins --lib --examples --all-features
|
args: --workspace --bins --lib --examples --all-features
|
||||||
if: ${{ !env.ACT }} # skip during local actions testing
|
if: ${{ !env.ACT }} # skip during local actions testing
|
||||||
- name: Run clippy (local)
|
- name: Run clippy (local)
|
||||||
run: cargo clippy --verbose --bins --lib --examples --all-features
|
run: cargo clippy --workspace --verbose --bins --lib --examples --all-features
|
||||||
if: ${{ env.ACT }} # only run during local actions testing
|
if: ${{ env.ACT }} # only run during local actions testing
|
||||||
doc:
|
doc:
|
||||||
name: "Check rustdoc"
|
name: "Check rustdoc"
|
||||||
|
|
@ -121,6 +121,6 @@ jobs:
|
||||||
shared-key: "cargo-deps"
|
shared-key: "cargo-deps"
|
||||||
cache-targets: false
|
cache-targets: false
|
||||||
- name: "Run cargo doc"
|
- name: "Run cargo doc"
|
||||||
run: cargo doc
|
run: cargo doc --workspace
|
||||||
env:
|
env:
|
||||||
RUSTDOCFLAGS: "-D warnings"
|
RUSTDOCFLAGS: "-D warnings"
|
||||||
|
|
|
||||||
2
.github/workflows/node-badge.yml
vendored
2
.github/workflows/node-badge.yml
vendored
|
|
@ -39,7 +39,7 @@ jobs:
|
||||||
# Calculate how many of those games we have definitions for
|
# Calculate how many of those games we have definitions for
|
||||||
rust_games_count=0
|
rust_games_count=0
|
||||||
for game in $node_games; do
|
for game in $node_games; do
|
||||||
if grep "\"$game\" *=>" ./src/games/definitions.rs; then
|
if grep "\"$game\" *=>" ./crates/lib/src/games/definitions.rs; then
|
||||||
rust_games_count=$(( rust_games_count + 1 ))
|
rust_games_count=$(( rust_games_count + 1 ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -8,25 +8,25 @@ repos:
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: rustup run --install nightly-2023-07-09 cargo-clippy -- -- -D warnings
|
entry: rustup run --install nightly-2023-07-09 cargo-clippy -- --workspace --all-features -- -D warnings
|
||||||
- id: build-no-features
|
- id: build-no-features
|
||||||
name: Check crate build with no features
|
name: Check crate build with no features
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: cargo build --no-default-features
|
entry: cargo check --workspace --no-default-features
|
||||||
- id: build-all-features
|
- id: build-all-features
|
||||||
name: Check crate builds with all features
|
name: Check crate builds with all features
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: cargo build --all-features --lib --bins --examples
|
entry: cargo check --workspace --all-features --lib --bins --examples
|
||||||
- id: test
|
- id: test
|
||||||
name: Check tests pass
|
name: Check tests pass
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: cargo test --bins --lib --examples --all-features
|
entry: cargo test --workspace --bins --lib --examples --all-features
|
||||||
- id: format
|
- id: format
|
||||||
name: Check rustfmt
|
name: Check rustfmt
|
||||||
language: system
|
language: system
|
||||||
|
|
@ -34,11 +34,11 @@ repos:
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: rustup run --install nightly-2023-07-09 cargo-fmt --check
|
entry: rustup run --install nightly-2023-07-09 cargo-fmt --check
|
||||||
- id: msrv
|
- id: msrv
|
||||||
name: Check MSRV compiles
|
name: Check MSRV compiles (lib only)
|
||||||
language: system
|
language: system
|
||||||
files: '[.]rs$'
|
files: '[.]rs$'
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
entry: rustup run --install 1.65 cargo build
|
entry: rustup run --install 1.65 cargo check -p gamedig
|
||||||
- id: docs
|
- id: docs
|
||||||
name: Check rustdoc compiles
|
name: Check rustdoc compiles
|
||||||
language: system
|
language: system
|
||||||
|
|
|
||||||
44
Cargo.toml
44
Cargo.toml
|
|
@ -1,35 +1,15 @@
|
||||||
[package]
|
[workspace]
|
||||||
name = "gamedig"
|
name = "gamedig-workspace"
|
||||||
version = "0.4.1"
|
members = ["crates/cli", "crates/lib"]
|
||||||
edition = "2021"
|
|
||||||
authors = [
|
|
||||||
"rust-GameDig contributors [https://github.com/gamedig/rust-gamedig/contributors]",
|
|
||||||
"node-GameDig contributors [https://github.com/gamedig/node-gamedig/contributors]",
|
|
||||||
]
|
|
||||||
license = "MIT"
|
|
||||||
description = "Query game servers and not only."
|
|
||||||
homepage = "https://github.com/gamedig/rust-gamedig"
|
|
||||||
documentation = "https://docs.rs/gamedig/latest/gamedig/"
|
|
||||||
repository = "https://github.com/gamedig/rust-gamedig"
|
|
||||||
readme = "README.md"
|
|
||||||
keywords = ["server", "query", "game", "check", "status"]
|
|
||||||
rust-version = "1.65.0"
|
|
||||||
categories = ["parser-implementations", "parsing", "network-programming", "encoding"]
|
|
||||||
|
|
||||||
[features]
|
# Edition 2021, uses resolver = 2
|
||||||
default = ["games", "services", "game_defs"]
|
resolver = "2"
|
||||||
games = []
|
|
||||||
services = []
|
|
||||||
game_defs = ["dep:phf", "games"]
|
|
||||||
serde = ["dep:serde", "serde/derive"]
|
|
||||||
|
|
||||||
[dependencies]
|
[profile.release]
|
||||||
byteorder = "1.5"
|
opt-level = 3
|
||||||
bzip2-rs = "0.1"
|
debug = false
|
||||||
crc32fast = "1.3"
|
rpath = true
|
||||||
serde_json = "1.0"
|
lto = true
|
||||||
encoding_rs = "0.8"
|
|
||||||
|
|
||||||
serde = { version = "1.0", optional = true }
|
[profile.release.package."*"]
|
||||||
|
opt-level = 3
|
||||||
phf = { version = "0.11", optional = true, features = ["macros"] }
|
|
||||||
|
|
|
||||||
16
crates/cli/Cargo.toml
Normal file
16
crates/cli/Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[package]
|
||||||
|
name = "gamedig-cli"
|
||||||
|
authors = [
|
||||||
|
"rust-GameDig contributors [https://github.com/gamedig/rust-gamedig/contributors]",
|
||||||
|
]
|
||||||
|
description = "A command line interface for gamedig"
|
||||||
|
license = "MIT"
|
||||||
|
version = "0.4.1"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4.1.11", features = ["derive"] }
|
||||||
|
gamedig = { version = "*", path = "../lib" }
|
||||||
|
thiserror = "1.0.43"
|
||||||
16
crates/cli/src/error.rs
Normal file
16
crates/cli/src/error.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error("IO Error: {0}")]
|
||||||
|
Io(#[from] std::io::Error),
|
||||||
|
|
||||||
|
#[error("Clap Error: {0}")]
|
||||||
|
Clap(#[from] clap::Error),
|
||||||
|
|
||||||
|
#[error("Gamedig Error: {0}")]
|
||||||
|
Gamedig(#[from] gamedig::errors::GDError),
|
||||||
|
|
||||||
|
#[error("Unknown Game: {0}")]
|
||||||
|
UnknownGame(String),
|
||||||
|
}
|
||||||
34
crates/cli/src/main.rs
Normal file
34
crates/cli/src/main.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
use std::net::IpAddr;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
use gamedig::games::*;
|
||||||
|
|
||||||
|
mod error;
|
||||||
|
|
||||||
|
use self::error::Result;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(author, version, about)]
|
||||||
|
struct Cli {
|
||||||
|
#[arg(short, long)]
|
||||||
|
game: String,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
ip: IpAddr,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
port: Option<u16>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let args = Cli::parse();
|
||||||
|
|
||||||
|
let game = match GAMES.get(&args.game) {
|
||||||
|
Some(game) => game,
|
||||||
|
None => return Err(error::Error::UnknownGame(args.game)),
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("{:#?}", query(game, &args.ip, args.port)?.as_json());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
35
crates/lib/Cargo.toml
Normal file
35
crates/lib/Cargo.toml
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
[package]
|
||||||
|
name = "gamedig"
|
||||||
|
version = "0.4.1"
|
||||||
|
edition = "2021"
|
||||||
|
authors = [
|
||||||
|
"rust-GameDig contributors [https://github.com/gamedig/rust-gamedig/contributors]",
|
||||||
|
"node-GameDig contributors [https://github.com/gamedig/node-gamedig/contributors]",
|
||||||
|
]
|
||||||
|
license = "MIT"
|
||||||
|
description = "Query game servers and not only."
|
||||||
|
homepage = "https://github.com/gamedig/rust-gamedig"
|
||||||
|
documentation = "https://docs.rs/gamedig/latest/gamedig/"
|
||||||
|
repository = "https://github.com/gamedig/rust-gamedig"
|
||||||
|
readme = "README.md"
|
||||||
|
keywords = ["server", "query", "game", "check", "status"]
|
||||||
|
rust-version = "1.65.0"
|
||||||
|
categories = ["parser-implementations", "parsing", "network-programming", "encoding"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["games", "services", "game_defs"]
|
||||||
|
games = []
|
||||||
|
services = []
|
||||||
|
game_defs = ["dep:phf", "games"]
|
||||||
|
serde = ["dep:serde", "serde/derive"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
byteorder = "1.5"
|
||||||
|
bzip2-rs = "0.1"
|
||||||
|
crc32fast = "1.3"
|
||||||
|
serde_json = "1.0"
|
||||||
|
encoding_rs = "0.8"
|
||||||
|
|
||||||
|
serde = { version = "1.0", optional = true }
|
||||||
|
|
||||||
|
phf = { version = "0.11", optional = true, features = ["macros"] }
|
||||||
Loading…
Add table
Add a link
Reference in a new issue