Add basic `clap` support

finchie
Oct 22, 2023, 9:09 AM
BMG4FSHNV54VXDHNUVGZOMXQJWLFSUF3M5NCN7GJETNIF3QTHELQC

Dependencies

  • [2] C73UJ7ZY Create simple `xilem_html` demo

Change contents

  • replacement in src/main.rs at line 1
    [2.49][2.50:189]()
    extern crate xilem_html;
    use xilem_html::{
    document_body, elements as el,
    events::{self as evt},
    App, Event, View, ViewExt,
    };
    [2.49]
    [2.189]
    use xilem_html::{document_body, elements as el, App, View, ViewExt};
    pub mod cli;
    use clap::{ArgMatches, CommandFactory};
    use cli::MockApp;
  • edit in src/main.rs at line 10
    [2.248]
    [2.248]
    matches: Option<Result<ArgMatches, clap::Error>>,
  • edit in src/main.rs at line 16
    [2.359][2.359:367]()
    }
    }
  • replacement in src/main.rs at line 17
    [2.368][2.368:629]()
    fn command_item<A, F>(
    label: &'static str,
    click_fn: F,
    ) -> evt::OnClick<AppState, A, el::Button<&'static str>, F, ()>
    where
    F: Fn(&mut AppState, &Event<web_sys::MouseEvent, web_sys::HtmlButtonElement>),
    {
    el::button(label).on_click(click_fn)
    [2.368]
    [2.629]
    let cli_command = MockApp::command();
    let args_iter = self.command.split(' ');
    let matches = cli_command.try_get_matches_from(args_iter);
    self.matches = Some(matches);
    }
  • edit in src/main.rs at line 28
    [2.807]
    [2.807]
  • replacement in src/main.rs at line 32
    [2.941][2.941:1003]()
    el::span(format!("Command is: `{}`", state.command)),
    [2.941]
    [2.1003]
    el::span(format!("Command is: `{:#?}`", state.matches)),
  • file addition: cli.rs (----------)
    [2.15]
    use clap::Parser;
    // An example command-line definition for prototyping
    #[derive(Parser, Debug)]
    #[command(author, version, about, long_about = None, name = "pijul")]
    pub struct MockApp {
    /// Name of the person to greet
    #[arg(short, long)]
    name: String,
    /// Number of times to greet
    #[arg(short, long, default_value_t = 1)]
    count: u8,
    }
  • edit in Cargo.toml at line 4
    [2.1329]
    [2.1329]
    edition = "2021"
  • edit in Cargo.toml at line 7
    [2.1345]
    [2.1345]
    clap = { version = "4.4.6", features = ["derive"] }
  • edit in Cargo.lock at line 4
    [2.1614]
    [2.1614]
    [[package]]
    name = "anstream"
    version = "0.6.4"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
    dependencies = [
    "anstyle",
    "anstyle-parse",
    "anstyle-query",
    "anstyle-wincon",
    "colorchoice",
    "utf8parse",
    ]
    [[package]]
    name = "anstyle"
    version = "1.0.4"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
    [[package]]
    name = "anstyle-parse"
    version = "0.2.2"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140"
    dependencies = [
    "utf8parse",
    ]
    [[package]]
    name = "anstyle-query"
    version = "1.0.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
    dependencies = [
    "windows-sys",
    ]
    [[package]]
    name = "anstyle-wincon"
    version = "3.0.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
    dependencies = [
    "anstyle",
    "windows-sys",
    ]
  • edit in Cargo.lock at line 78
    [2.2393]
    [2.2393]
    name = "clap"
    version = "4.4.6"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956"
    dependencies = [
    "clap_builder",
    "clap_derive",
    ]
    [[package]]
    name = "clap_builder"
    version = "4.4.6"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45"
    dependencies = [
    "anstream",
    "anstyle",
    "clap_lex",
    "strsim",
    ]
    [[package]]
    name = "clap_derive"
    version = "4.4.2"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
    dependencies = [
    "heck",
    "proc-macro2",
    "quote",
    "syn",
    ]
    [[package]]
    name = "clap_lex"
    version = "0.5.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
    [[package]]
    name = "colorchoice"
    version = "1.0.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
    [[package]]
  • edit in Cargo.lock at line 165
    [2.3394]
    [2.3394]
    [[package]]
    name = "heck"
    version = "0.4.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
  • edit in Cargo.lock at line 206
    [2.4286]
    [2.4286]
    "clap",
  • edit in Cargo.lock at line 275
    [2.5934]
    [2.5934]
    name = "strsim"
    version = "0.10.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
    [[package]]
  • edit in Cargo.lock at line 298
    [2.6383]
    [2.6383]
    name = "utf8parse"
    version = "0.2.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
    [[package]]
  • edit in Cargo.lock at line 368
    [2.7968]
    [2.7968]
    name = "windows-sys"
    version = "0.48.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
    dependencies = [
    "windows-targets",
    ]
    [[package]]
    name = "windows-targets"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
    dependencies = [
    "windows_aarch64_gnullvm",
    "windows_aarch64_msvc",
    "windows_i686_gnu",
    "windows_i686_msvc",
    "windows_x86_64_gnu",
    "windows_x86_64_gnullvm",
    "windows_x86_64_msvc",
    ]
    [[package]]
    name = "windows_aarch64_gnullvm"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
    [[package]]
    name = "windows_aarch64_msvc"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
    [[package]]
    name = "windows_i686_gnu"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
    [[package]]
    name = "windows_i686_msvc"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
    [[package]]
    name = "windows_x86_64_gnu"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
    [[package]]
    name = "windows_x86_64_gnullvm"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
    [[package]]
    name = "windows_x86_64_msvc"
    version = "0.48.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
    [[package]]