diff --git a/courses/rust/building-blocks/bb-1.md b/courses/rust/building-blocks/bb-1.md index bf680832c..1c6b2e249 100644 --- a/courses/rust/building-blocks/bb-1.md +++ b/courses/rust/building-blocks/bb-1.md @@ -12,6 +12,9 @@ Read all the readings and perform all the exercises. techniques used by this author may provide an interesting contrast to those we suggest. Follow along and write the same code. Can you reproduce their results? + - The following content may be useful for you to understand the above `Exercise` and dive into rust's CLI ecosystem. + + **[Reading: Official Documentation of `clap`]** - **[Reading: The Cargo manifest format]**. A single page in [The Cargo Book], this will give you an idea of how your project can be customized a bit if you @@ -41,4 +44,4 @@ Read all the readings and perform all the exercises. [`rust-lang-nursery`]: https://github.com/rust-lang-nursery [Reading: The rustup documentation]: https://github.com/rust-lang/rustup.rs/blob/master/README.md [Exercise: Write a Good CLI Program]: https://qiita.com/tigercosmos/items/678f39b1209e60843cc3 - +[Reading: Official Documentation of `clap`]: https://docs.rs/clap/3.0.0-beta.2/clap/index.html diff --git a/courses/rust/projects/project-1/Cargo.lock b/courses/rust/projects/project-1/Cargo.lock index 16d613e88..2ac25eeff 100644 --- a/courses/rust/projects/project-1/Cargo.lock +++ b/courses/rust/projects/project-1/Cargo.lock @@ -11,25 +11,18 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - [[package]] name = "assert_cmd" -version = "0.11.1" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc477793bd82ec39799b6f6b3df64938532fdf2ab0d49ef817eac65856a5a1e" +checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e" dependencies = [ - "escargot", + "bstr", + "doc-comment", "predicates", "predicates-core", "predicates-tree", + "wait-timeout", ] [[package]] @@ -50,64 +43,103 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" [[package]] -name = "bitflags" +name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "cfg-if" -version = "0.1.9" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", +] [[package]] name = "clap" -version = "2.33.0" +version = "3.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "9f1fe12880bae935d142c8702d500c63a4e8634b6c3c57ad72bf978fc7b6249a" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_lex", + "indexmap", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", ] [[package]] -name = "difference" -version = "2.0.0" +name = "clap_lex" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" +checksum = "87eba3c8c7f42ef17f6c659fc7416d0f4758cd3e58861ee63c5fa4a4dde649e4" +dependencies = [ + "os_str_bytes", +] [[package]] -name = "escargot" +name = "difflib" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceb9adbf9874d5d028b5e4c5739d22b71988252b25c9c98fe7cf9738bee84597" -dependencies = [ - "lazy_static", - "log", - "serde", - "serde_json", -] +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "float-cmp" -version = "0.4.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" dependencies = [ "num-traits", ] [[package]] -name = "itoa" -version = "0.4.4" +name = "hashbrown" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg 1.1.0", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] [[package]] name = "kvs" @@ -130,15 +162,6 @@ version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" -[[package]] -name = "log" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" -dependencies = [ - "cfg-if", -] - [[package]] name = "memchr" version = "2.5.0" @@ -147,9 +170,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "normalize-line-endings" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "num-traits" @@ -157,7 +180,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" dependencies = [ - "autocfg", + "autocfg 0.1.4", ] [[package]] @@ -166,14 +189,21 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +[[package]] +name = "os_str_bytes" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" + [[package]] name = "predicates" -version = "1.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e09015b0d3f5a0ec2d4428f7559bb7b3fff341b4e159fedd1d57fac8b939ff" +checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" dependencies = [ - "difference", + "difflib", "float-cmp", + "itertools", "normalize-line-endings", "predicates-core", "regex", @@ -195,24 +225,6 @@ dependencies = [ "treeline", ] -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" -dependencies = [ - "proc-macro2", -] - [[package]] name = "redox_syscall" version = "0.1.54" @@ -240,63 +252,30 @@ dependencies = [ ] [[package]] -name = "regex-syntax" -version = "0.6.26" +name = "regex-automata" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] -name = "ryu" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" - -[[package]] -name = "serde" -version = "1.0.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a3223d0c9ba936b61c0d2e3e559e3217dbfb8d65d06d26e8b3c25de38bae3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.39" +name = "regex-syntax" +version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" -dependencies = [ - "itoa", - "ryu", - "serde", -] +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] -name = "syn" -version = "0.15.35" +name = "termcolor" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "641e117d55514d6d918490e47102f7e08d096fdde360247e4a10f7a91a8478d3" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "winapi-util", ] [[package]] @@ -313,12 +292,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.11.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "treeline" @@ -327,22 +303,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] -name = "unicode-width" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" - -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - -[[package]] -name = "vec_map" -version = "0.8.1" +name = "wait-timeout" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] [[package]] name = "winapi" @@ -360,6 +327,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/courses/rust/projects/project-1/Cargo.toml b/courses/rust/projects/project-1/Cargo.toml index f175f3fb6..6b8997c30 100644 --- a/courses/rust/projects/project-1/Cargo.toml +++ b/courses/rust/projects/project-1/Cargo.toml @@ -3,11 +3,11 @@ name = "kvs" version = "0.1.0" authors = ["Yilin Chen "] description = "A key-value store" -edition = "2018" +edition = "2021" [dependencies] -clap = "2.32.0" +clap = "3.2.6" [dev-dependencies] -assert_cmd = "0.11.0" -predicates = "1.0.0" +assert_cmd = "2.0.4" +predicates = "2.1.1" diff --git a/courses/rust/projects/project-1/src/bin/kvs.rs b/courses/rust/projects/project-1/src/bin/kvs.rs index 2831e95fc..247a01585 100644 --- a/courses/rust/projects/project-1/src/bin/kvs.rs +++ b/courses/rust/projects/project-1/src/bin/kvs.rs @@ -8,7 +8,6 @@ fn main() { .about(env!("CARGO_PKG_DESCRIPTION")) .setting(AppSettings::DisableHelpSubcommand) .setting(AppSettings::SubcommandRequiredElseHelp) - .setting(AppSettings::VersionlessSubcommands) .subcommand( SubCommand::with_name("set") .about("Set the value of a string key to a string") @@ -32,15 +31,15 @@ fn main() { .get_matches(); match matches.subcommand() { - ("set", Some(_matches)) => { + Some(("set", _matches)) => { eprintln!("unimplemented"); exit(1); } - ("get", Some(_matches)) => { + Some(("get", _matches)) => { eprintln!("unimplemented"); exit(1); } - ("rm", Some(_matches)) => { + Some(("rm", _matches)) => { eprintln!("unimplemented"); exit(1); }