diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 56bbb8e..155e830 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,8 +14,3 @@ updates: directory: "/" # Location of package manifests schedule: interval: "daily" - - - package-ecosystem: "cargo" # See documentation for possible values - directory: "/suggestion/" # Location of package manifests - schedule: - interval: "daily" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9de58ae..0609230 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -4,7 +4,6 @@ on: push: branches: [ main ] pull_request: - branches: [ main ] env: CARGO_TERM_COLOR: always @@ -20,17 +19,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Build run: cargo build --verbose - - name: Run tests - run: cargo test --verbose - - - name: Run tests on suggesion/ - run: cargo test --verbose - working-directory: suggestion - run: strategy: fail-fast: false @@ -44,3 +35,30 @@ jobs: - run: cargo run instakk update install - run: cargo run install update install && exit 1 || exit 0 - run: cargo run hoge update install && exit 1 || exit 0 + + format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - run: cargo fmt --all -- --check + + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-targets --all-features -- -D clippy::all -D warnings + + test: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index 8d41889..272498f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,9 +15,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" @@ -27,9 +27,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "clap" -version = "3.0.13" +version = "3.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08799f92c961c7a1cf0cc398a9073da99e21ce388b46372c37f3191f2f3eed3e" +checksum = "86f8c0e2a6b902acc18214e24a6935cdaf8a8e34231913d4404dcaee659f65a1" dependencies = [ "atty", "bitflags", @@ -44,9 +44,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.0.12" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd2078197a22f338bd4fbf7d6387eb6f0d6a3c69e6cbc09f5c93e97321fd92a" +checksum = "01d42c94ce7c2252681b5fed4d3627cc807b13dfc033246bd05d5b252399000e" dependencies = [ "heck", "proc-macro-error", @@ -100,9 +100,9 @@ checksum = "72d9d1bd215936bc8647ad92986bb56f3f216550b53c44ab785e3217ae33625e" [[package]] name = "libc" -version = "0.2.116" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" [[package]] name = "memchr" @@ -169,17 +169,10 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "suggestion" -version = "0.3.0" -dependencies = [ - "lev_distance", -] - -[[package]] -name = "suggestion-cli" -version = "0.3.1" +version = "0.3.2" dependencies = [ "clap", - "suggestion", + "lev_distance", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index faff94e..f32977b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,18 @@ [package] -name = "suggestion-cli" -version = "0.3.1" +name = "suggestion" +version = "0.3.2" edition = "2021" authors = ["Ken Matsui <26405363+ken-matsui@users.noreply.github.com>"] -description = "A CLI tool for similar name suggestions to provide helps like \"Did you mean?\"" +description = "A minimal library & CLI tool to provide similar name suggestions like \"Did you mean?\"" license = "MIT" readme = "README.md" repository = "https://github.com/ken-matsui/suggestion/" homepage = "https://github.com/ken-matsui/suggestion#readme" -documentation = "https://docs.rs/suggestion-cli" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[workspace] -members = ["suggestion"] +documentation = "https://docs.rs/suggestion" [dependencies] clap = { version = "3.0.13", features = ["derive"] } -suggestion = { path = "suggestion", version = "0.3.0" } +lev_distance = "0.1.1" [[bin]] name = "suggest" diff --git a/README.md b/README.md index ff6a761..04fc393 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,106 @@ -# suggestion-cli [![crates.io version](https://img.shields.io/crates/v/suggestion-cli.svg)](https://crates.io/crates/suggestion-cli) [![crates.io downloads](https://img.shields.io/crates/d/suggestion-cli.svg)](https://crates.io/crates/suggestion-cli) +# suggestion [![crates.io version](https://img.shields.io/crates/v/suggestion.svg)](https://crates.io/crates/suggestion) [![crates.io downloads](https://img.shields.io/crates/d/suggestion.svg)](https://crates.io/crates/suggestion) -A CLI tool for similar name suggestions to provide helps like "Did you mean?" +A minimal library & CLI tool to provide similar name suggestions like "Did you mean?" +This library provides suggestion traits for all collection types in the standard library. -The library version is placed [here](./suggestion). +## Examples + +### Simple case + +This example can be executed by the `cargo run --example simple` command. + +```rust +use suggestion::Suggest; + +fn main() { + let input = "instakk"; + + let list_commands = vec!["update", "install"]; + if list_commands.contains(&input) { + return; + } + + if let Some(sugg) = list_commands.suggest(input) { + println!("No command named `{}` found.", input); + println!("Did you mean `{}`?", sugg); + } +} +``` -## Installation +```shell +$ cargo run +No command named `instakk` found. +Did you mean `install`? +``` + +### Specifying distance + +```rust +use suggestion::Suggest; + +fn main() { + let input = "paoc"; + + let list_commands = vec!["poac", "poacpp"]; + if list_commands.contains(&input) { + return; + } + + if let Some(sugg) = list_commands.suggest_with_dist(input, Some(2)) { + println!("No command named `{}` found.", input); + println!("Did you mean `{}`?", sugg); + } +} +``` + +```shell +$ cargo run +No command named `paoc` found. +Did you mean `poac`? +``` + +## Supported types + +Please let me know if anything is left out through issues or pull requests. + +### Sequences + +* `LinkedList` +* `VecDeque` +* `Vec` + +### Maps + +* `HashMap` +* `BTreeMap` + +To suggest keys, use `suggestion::SuggestKey` trait. + +### Sets + +* `BTreeSet` +* `HashSet` + +### Misc + +* `BinaryHeap` +* `[T; N]`: primitive array +* `[T]`: slices + +## CLI + +### Installation ```bash -cargo install suggestion-cli +cargo install suggestion ``` -## Usage +### Usage ```bash $ suggest --help -suggestion-cli 0.3.1 -A CLI tool for similar name suggestions to provide helps like "Did you mean?" +suggestion 0.3.1 +A minimal library & CLI tool to provide similar name suggestions like "Did you mean?" USAGE: suggest [OPTIONS] [VALUES]... @@ -31,7 +116,7 @@ OPTIONS: -V, --version Print version information ``` -## Examples +### Examples ```bash $ suggest instakk update install diff --git a/suggestion/examples/simple.rs b/examples/simple.rs similarity index 100% rename from suggestion/examples/simple.rs rename to examples/simple.rs diff --git a/suggestion/src/lib.rs b/src/lib.rs similarity index 94% rename from suggestion/src/lib.rs rename to src/lib.rs index 7e38866..c85451b 100644 --- a/suggestion/src/lib.rs +++ b/src/lib.rs @@ -175,15 +175,13 @@ mod tests { ($t:ident, $f:ident) => { #[test] fn $f() { - use std::array::IntoIter; - - let input = $t::<_, _>::from_iter(IntoIter::new([("aaab", 2), ("aaabc", 4)])); + let input = $t::<_, _>::from_iter([("aaab", 2), ("aaabc", 4)].into_iter()); assert_eq!(input.suggest_key("aaaa"), Some("aaab".to_string())); - let input = $t::<_, _>::from_iter(IntoIter::new([(2, "aaab"), (4, "aaabc")])); + let input = $t::<_, _>::from_iter([(2, "aaab"), (4, "aaabc")].into_iter()); assert_eq!(input.suggest("aaaa"), Some("aaab".to_string())); - let input = $t::<_, _>::from_iter(IntoIter::new([("poac", 2), ("poacpp", 4)])); + let input = $t::<_, _>::from_iter([("poac", 2), ("poacpp", 4)].into_iter()); assert_eq!(input.suggest_key("paoc"), None); assert_eq!(input.suggest_key_with_dist("paoc", Some(1)), None); assert_eq!( @@ -191,7 +189,7 @@ mod tests { Some("poac".to_string()) ); - let input = $t::<_, _>::from_iter(IntoIter::new([(2, "poac"), (4, "poacpp")])); + let input = $t::<_, _>::from_iter([(2, "poac"), (4, "poacpp")].into_iter()); assert_eq!(input.suggest("paoc"), None); assert_eq!(input.suggest_with_dist("paoc", Some(1)), None); assert_eq!( diff --git a/suggestion/.gitignore b/suggestion/.gitignore deleted file mode 100644 index 96ef6c0..0000000 --- a/suggestion/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -Cargo.lock diff --git a/suggestion/Cargo.toml b/suggestion/Cargo.toml deleted file mode 100644 index c92a318..0000000 --- a/suggestion/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "suggestion" -version = "0.3.0" -edition = "2021" -authors = ["Ken Matsui <26405363+ken-matsui@users.noreply.github.com>"] -description = "A minimal library for similar name suggestions to provide helps like \"Did you mean?\"" -license = "MIT" -readme = "README.md" -repository = "https://github.com/ken-matsui/suggestion/tree/main/suggestion/" -homepage = "https://github.com/ken-matsui/suggestion/tree/main/suggestion#readme" -documentation = "https://docs.rs/suggestion" - -[dependencies] -lev_distance = "0.1.1" diff --git a/suggestion/README.md b/suggestion/README.md deleted file mode 100644 index 7854ac6..0000000 --- a/suggestion/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# suggestion [![crates.io version](https://img.shields.io/crates/v/suggestion.svg)](https://crates.io/crates/suggestion) [![crates.io downloads](https://img.shields.io/crates/d/suggestion.svg)](https://crates.io/crates/suggestion) - -A minimal library for similar name suggestions to provide helps like "Did you mean?" -This library provides suggestion traits for all collection types in the standard library. - -## Examples - -### Simple case - -This example can be executed by the `cargo run --example simple` command. - -```rust -use suggestion::Suggest; - -fn main() { - let input = "instakk"; - - let list_commands = vec!["update", "install"]; - if list_commands.contains(&input) { - return; - } - - if let Some(sugg) = list_commands.suggest(input) { - println!("No command named `{}` found.", input); - println!("Did you mean `{}`?", sugg); - } -} -``` - -```shell -$ cargo run -No command named `instakk` found. -Did you mean `install`? -``` - -### Specifying distance - -```rust -use suggestion::Suggest; - -fn main() { - let input = "paoc"; - - let list_commands = vec!["poac", "poacpp"]; - if list_commands.contains(&input) { - return; - } - - if let Some(sugg) = list_commands.suggest_with_dist(input, Some(2)) { - println!("No command named `{}` found.", input); - println!("Did you mean `{}`?", sugg); - } -} -``` - -```shell -$ cargo run -No command named `paoc` found. -Did you mean `poac`? -``` - -## Supported types - -Please let me know if anything is left out through issues or pull requests. - -### Sequences - -* `LinkedList` -* `VecDeque` -* `Vec` - -### Maps - -* `HashMap` -* `BTreeMap` - -To suggest keys, use `suggestion::SuggestKey` trait. - -### Sets - -* `BTreeSet` -* `HashSet` - -### Misc - -* `BinaryHeap` -* `[T; N]`: primitive array -* `[T]`: slices - -## Contribution - -Contributions, including issues and pull requests, are very welcome.