Skip to content

Commit

Permalink
refactor: move binary to hugr-cli (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored May 29, 2024
1 parent 74a25be commit d0cd023
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
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]
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"]

0 comments on commit d0cd023

Please sign in to comment.