Render argument state as HTML

finchie
Oct 24, 2023, 12:44 PM
REI53XR4WDH5EKLTXTFVTOVWCCFRWTFH4GQS6DSNM5LSRFTX7HJQC

Dependencies

  • [2] JFJVY57R List `clap` argument IDs
  • [3] C73UJ7ZY Create simple `xilem_html` demo
  • [4] BMG4FSHN Add basic `clap` support

Change contents

  • replacement in src/main.rs at line 4
    [3.83][3.83:123]()
    use clap::{ArgMatches, CommandFactory};
    [3.83]
    [3.123]
    use clap::{parser::ValueSource, CommandFactory};
    use clap_builder::{parser::MatchedArg, util::any_value::AnyValueId};
  • replacement in src/main.rs at line 11
    [3.248][3.142:196](),[3.196][2.82:108]()
    matches: Option<Result<ArgMatches, clap::Error>>,
    arg_ids: Vec<String>,
    [3.248]
    [3.248]
    args: Vec<ArgState>,
    }
    struct ArgState {
    name: String,
    source: ValueSource,
    raw_values: Vec<String>,
    // Keep the value as a string, but store its corresponding type info
    type_id: AnyValueId,
  • edit in src/main.rs at line 29
    [3.359]
    [2.109]
    tracing::debug!("Matches: {:#?}", matches);
  • replacement in src/main.rs at line 31
    [2.110][2.110:229]()
    self.arg_ids = if let Ok(args) = &matches {
    args.ids().map(|id| id.as_str().to_string()).collect()
    [2.110]
    [2.229]
    // TODO: should be able to incrementally parse eventually
    self.args = if let Ok(matches) = matches {
    matches.args.iter().map(matched_to_state).collect()
  • edit in src/main.rs at line 37
    [2.280]
    [2.280]
    }
    }
    fn matched_to_state(key_value: (&clap::Id, &MatchedArg)) -> ArgState {
    let (key, value) = key_value;
  • replacement in src/main.rs at line 43
    [2.281][3.359:397](),[3.359][3.359:397]()
    self.matches = Some(matches);
    [2.281]
    [3.397]
    ArgState {
    name: key.to_string(),
    source: value.source().unwrap_or(ValueSource::DefaultValue),
    raw_values: value
    .raw_vals()
    .flatten()
    .map(|raw_value| raw_value.to_string_lossy().to_string())
    .collect(),
    type_id: value
    .type_id()
    .unwrap_or(AnyValueId::of::<dyn std::any::Any>()),
  • replacement in src/main.rs at line 57
    [3.632][2.282:371]()
    fn arg_item(id: &String) -> impl View<AppState> + ViewMarker {
    el::li(id.to_owned())
    [3.632]
    [2.371]
    fn arg_item(arg: &ArgState) -> impl View<AppState> + ViewMarker {
    let source = match arg.source {
    ValueSource::DefaultValue => "default",
    ValueSource::EnvVariable => "environment",
    ValueSource::CommandLine => "cmdline",
    _ => "todo",
    };
    el::div((
    el::h2(arg.name.clone()),
    el::div((
    format!("{:?}", arg.type_id),
    el::div("test").attr("class", "hover_content"),
    ))
    .attr("class", "hoverable"),
    el::div(source),
    el::ul(
    arg.raw_values
    .iter()
    .map(|arg| el::li(arg.clone()))
    .collect::<Vec<_>>(),
    ),
    ))
  • replacement in src/main.rs at line 82
    [3.692][3.692:722]()
    let input = el::input(())
    [3.692]
    [3.722]
    let input = el::input("")
  • replacement in src/main.rs at line 84
    [3.773][3.773:807](),[3.807][2.375:496]()
    .attr("autofocus", true);
    let arg_items = state
    .arg_ids
    .iter()
    .map(|id| arg_item(id))
    .collect::<Vec<_>>();
    [3.773]
    [3.404]
    .attr("autofocus", true)
    .attr("id", "command_input");
  • replacement in src/main.rs at line 90
    [3.941][3.406:471](),[3.471][2.497:517](),[2.517][2.517:536]()
    el::span(format!("Command is: `{:#?}`", state.matches)),
    el::br(()),
    arg_items,
    [3.941]
    [3.1003]
    state.args.iter().map(arg_item).collect::<Vec<_>>(),
  • edit in src/main.rs at line 96
    [3.1071]
    [3.1071]
    tracing_wasm::set_as_global_default();
  • replacement in Cargo.toml at line 7
    [3.1345][3.886:938]()
    clap = { version = "4.4.6", features = ["derive"] }
    [3.1345]
    [3.1345]
    clap = { path = "../clap", features = ["derive"] }
    clap_builder = { path = "../clap/clap_builder" }
  • edit in Cargo.toml at line 10
    [3.1378]
    [3.1378]
    tracing = "0.1.40"
    tracing-wasm = "0.2.1"
  • edit in Cargo.lock at line 80
    [3.2178][3.2178:2321]()
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956"
  • edit in Cargo.lock at line 88
    [3.2426][3.2426:2569]()
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45"
  • edit in Cargo.lock at line 98
    [3.2689][3.2689:2832]()
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
  • edit in Cargo.lock at line 108
    [3.2943][3.2943:3086]()
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
  • edit in Cargo.lock at line 187
    [3.4030]
    [3.4030]
    [[package]]
    name = "lazy_static"
    version = "1.4.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
  • edit in Cargo.lock at line 205
    [3.3493]
    [3.4286]
    "clap_builder",
  • edit in Cargo.lock at line 207
    [3.4315]
    [3.4315]
    "tracing",
    "tracing-wasm",
  • edit in Cargo.lock at line 219
    [3.4555]
    [3.4555]
    [[package]]
    name = "pin-project-lite"
    version = "0.2.13"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
  • edit in Cargo.lock at line 279
    [3.5919]
    [3.5919]
    ]
    [[package]]
    name = "sharded-slab"
    version = "0.1.7"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
    dependencies = [
    "lazy_static",
  • edit in Cargo.lock at line 305
    [3.6170]
    [3.6170]
    ]
    [[package]]
    name = "thread_local"
    version = "1.1.7"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
    dependencies = [
    "cfg-if",
    "once_cell",
  • edit in Cargo.lock at line 318
    [3.6185]
    [3.6185]
    name = "tracing"
    version = "0.1.40"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
    dependencies = [
    "pin-project-lite",
    "tracing-attributes",
    "tracing-core",
    ]
    [[package]]
    name = "tracing-attributes"
    version = "0.1.27"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
    dependencies = [
    "proc-macro2",
    "quote",
    "syn",
    ]
    [[package]]
    name = "tracing-core"
    version = "0.1.32"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
    dependencies = [
    "once_cell",
    ]
    [[package]]
    name = "tracing-subscriber"
    version = "0.3.17"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
    dependencies = [
    "sharded-slab",
    "thread_local",
    "tracing-core",
    ]
    [[package]]
    name = "tracing-wasm"
    version = "0.2.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07"
    dependencies = [
    "tracing",
    "tracing-subscriber",
    "wasm-bindgen",
    ]
    [[package]]