Skip to content

Feat/cli as lib#78

Closed
YOU54F wants to merge 4 commits intopact-foundation:masterfrom
YOU54F:feat/cli_as_lib
Closed

Feat/cli as lib#78
YOU54F wants to merge 4 commits intopact-foundation:masterfrom
YOU54F:feat/cli_as_lib

Conversation

@YOU54F
Copy link
Member

@YOU54F YOU54F commented Oct 8, 2025

📝 Summary of Changes

Changes proposed in this pull request:

  • Modifications to allow pact-stub-server to be consumed as a library pact_stub_server_cli so it can be composed in other clis

⚠️ Items of Note

Part of a series of pull requests

💁 Example

Composed cli: https://github.com/YOU54F/pact_cli/blob/259a268dd9e7fa48ad03c088f7244af7a4c89493/src/cli.rs#L11-L29

pub fn build_cli() -> Command {
    let app = Command::new("pact_cli")
        .about("A pact cli tool")
        .subcommand(
            pact_broker_cli::cli::pact_broker_client::add_pact_broker_client_command()
                .name("pact-broker")
                .subcommand(add_standalone_broker_subcommand())
                .subcommand(add_docker_broker_subcommand()),
        )
        .args(pact_broker_cli::cli::add_logging_arguments())
        .subcommand(
            pact_broker_cli::cli::pactflow_client::add_pactflow_client_command().name("pactflow"),
        )
        .subcommand(add_completions_subcommand())
        .subcommand(pact_plugin_cli::Cli::command().name("plugin"))
        .subcommand(pact_mock_server_cli::setup_args().name("mock"))
        .subcommand(pact_verifier_cli::args::setup_app().name("verifier"))
        .subcommand(pact_stub_server_cli::build_args().name("stub"));
    app
}

Cargo toml: https://github.com/YOU54F/pact_cli/blob/259a268dd9e7fa48ad03c088f7244af7a4c89493/Cargo.toml#L67-L71

pact-stub-server = { version = "*", git = "https://github.com/YOU54F/pact-stub-server.git", branch = "feat/cli_as_lib"}
pact_mock_server_cli = { version = "2.0.0-beta.1", git = "https://github.com/YOU54F/pact-core-mock-server.git", branch = "feat/cli_as_lib"}
pact-plugin-cli = { version = "*", git = "https://github.com/YOU54F/pact-plugins", branch = "feat/cli_as_lib"}
pact_verifier_cli = { version = "*",  git = "https://github.com/YOU54F/pact-reference", branch = "feat/cli_as_lib"}
pact-broker-cli = { version = "*", git = "https://github.com/YOU54F/pact-broker-cli", branch = "main"}

🔨 How To Test

git clone git@github.com:YOU54F/pact_cli.git
cd pact_cli
git checkout multi-cli
RUSTFLAGS=-Awarnings cargo run -q --

output

A pact cli tool

Usage: pact_cli [OPTIONS] [COMMAND]

Commands:
  pact-broker  
  pactflow     
  completions  Generates completion scripts for your shell
  plugin       CLI utility for Pact plugins
  mock         Standalone Pact mock server
  verifier     Standalone pact verifier for provider pact verification
  stub         Pact Stub Server 0.6.3
  help         Print this message or the help of the given subcommand(s)

Options:
      --log-level <LEVEL>  Set the log level (none, off, error, warn, info, debug, trace) [default: off] [possible values: off, none, error, warn, info, debug, trace]
  -h, --help               Print help

usage

➜  pact_cli git:(multi-cli) RUSTFLAGS=-Awarnings cargo run -q -- stub -f tests/pacts/GettingStartedOrderWeb-GettingStartedOrderApi.json 
2025-10-08T21:45:53.218070Z  INFO main pact_stub_server_cli: Loaded 1 pacts (1 total interactions)
2025-10-08T21:45:53.218530Z  INFO tokio-runtime-worker pact_stub_server_cli::server: Server started on port 52196
2025-10-08T21:46:30.133081Z  INFO tokio-runtime-worker pact_stub_server_cli::server: ===> Received HTTP Request ( method: GET, path: /orders, query: None, headers: Some({"host": ["localhost:52196"], "accept": ["*/*"], "user-agent": ["curl/8.7.1"]}), body: Empty )
2025-10-08T21:46:30.135928Z  INFO tokio-runtime-worker pact_stub_server_cli::pact_support: <=== Sending HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json; charset=utf-8"]}), body: Present(63 bytes) )
➜  pact_cli git:(multi-cli) curl http://localhost:52196/orders
[{"id":1,"items":[{"name":"burger","quantity":2,"value":100}]}]%   

- operating-system: windows-2019
- operating-system: windows-latest
targets: aarch64-pc-windows-msvc,x86_64-pc-windows-msvc
- operating-system: macos-13
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macos-13 will be going soon, we can safely set this to macos-latest as we set the target with MACOSX_DEPLOYMENT_TARGET env var during the build

This was referenced Oct 24, 2025
@YOU54F
Copy link
Member Author

YOU54F commented Oct 31, 2025

merged as part of #81

@YOU54F YOU54F closed this Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant