Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move binary to hugr-cli #1134

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hugr-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ assert_cmd = { workspace = true }
assert_fs = { workspace = true }
predicates = { workspace = true }
rstest.workspace = true

[[bin]]
name = "hugr"
path = "src/main.rs"
34 changes: 31 additions & 3 deletions hugr-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,40 @@ hugr-cli
[![msrv][]](https://github.com/CQCL/hugr)
[![codecov][]](https://codecov.io/gh/CQCL/hugr)

This crate provides tooling used by the `hugr` CLI tool.
Refer to the [main crate](http://crates.io/crates/hugr) for more information.
`hugr` CLI tool for common tasks on serialised HUGR (e.g. validation,
visualisation).

Refer to the [main HUGR crate](http://crates.io/crates/hugr) for more information.

## Usage

Add the dependency to your project:
Install using `cargo`:

```bash
cargo install hugr-cli
```

This will install the `hugr` binary. Running `hugr --help` shows:

```
Validate a HUGR.

Usage: hugr [OPTIONS] <INPUT>

Arguments:
<INPUT>

Options:
-m, --mermaid Visualise with mermaid.
-n, --no-validate Skip validation.
-v, --verbose... Increase logging verbosity
-q, --quiet... Decrease logging verbosity
-h, --help Print help
-V, --version Print version
```


To extend the CLI you can also add the project as a library dependency:

```bash
cargo add hugr-cli
Expand Down
4 changes: 2 additions & 2 deletions hugr-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Standard command line tools, used by the hugr binary.

use clap::Parser;
use clap_stdin::FileOrStdin;
use clap_verbosity_flag::Level;
use clap_verbosity_flag::{InfoLevel, Verbosity};
use thiserror::Error;
/// We reexport some clap types that are used in the public API.
pub use {clap::Parser, clap_verbosity_flag::Level};

use hugr_core::{extension::ExtensionRegistry, Hugr, HugrView};

Expand Down
11 changes: 7 additions & 4 deletions hugr/src/main.rs → hugr-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
//! Validate serialized HUGR on the command line

use hugr::std_extensions::arithmetic::{
use hugr_core::std_extensions::arithmetic::{
conversions::EXTENSION as CONVERSIONS_EXTENSION, float_ops::EXTENSION as FLOAT_OPS_EXTENSION,
float_types::EXTENSION as FLOAT_TYPES_EXTENSION, int_ops::EXTENSION as INT_OPS_EXTENSION,
int_types::EXTENSION as INT_TYPES_EXTENSION,
};
use hugr::std_extensions::logic::EXTENSION as LOGICS_EXTENSION;
use hugr_core::std_extensions::logic::EXTENSION as LOGICS_EXTENSION;

use hugr::extension::{ExtensionRegistry, PRELUDE};
use hugr_core::extension::{ExtensionRegistry, PRELUDE};

use hugr_cli::{CmdLineArgs, Level, Parser};
use hugr_cli::CmdLineArgs;

use clap::Parser;
use clap_verbosity_flag::Level;

fn main() {
let opts = CmdLineArgs::parse();
Expand Down
3 changes: 1 addition & 2 deletions hugr/tests/cli.rs → hugr-cli/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(feature = "_cli")]
use assert_cmd::Command;
use assert_fs::{fixture::FileWriteStr, NamedTempFile};
use hugr_cli::VALID_PRINT;
Expand All @@ -15,7 +14,7 @@ use rstest::{fixture, rstest};

#[fixture]
fn cmd() -> Command {
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
Command::cargo_bin("hugr").unwrap()
}

#[fixture]
Expand Down
12 changes: 0 additions & 12 deletions hugr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,16 @@ path = "src/lib.rs"
[features]
extension_inference = []

# Definitions used by the `hugr` binary
_cli = ["dep:hugr-cli"]

[dependencies]
aborgna-q marked this conversation as resolved.
Show resolved Hide resolved
hugr-core = { path = "../hugr-core", version = "0.1.0" }
hugr-passes = { path = "../hugr-passes", version = "0.1.0" }
hugr-cli = { path = "../hugr-cli", version = "0.1.0", optional = true }

[dev-dependencies]
rstest = { workspace = true }
lazy_static = { workspace = true }
criterion = { workspace = true, features = ["html_reports"] }
serde_json = { workspace = true }
assert_cmd = { workspace = true }
assert_fs = { workspace = true }
predicates = { workspace = true }

[[bench]]
name = "bench_main"
harness = false


[[bin]]
name = "hugr"
required-features = ["_cli"]