Remove dependency on clap patches

finchie
Nov 16, 2023, 9:13 AM
G54GZBS464DFT2224SUTRWPRRSLUQKWDXY2YA7USW7UZ7VPXIHEAC

Dependencies

  • [2] OVEFU3K2 Implement basic Typst -> Rust function transpilation
  • [3] REI53XR4 Render argument state as HTML
  • [4] CQEA2ZDI Parse evaluated Typst code instead of AST
  • [5] ZYNEMGAZ Use generated Typst code from Rust
  • [6] Q3IYM4WF Add MVP table support
  • [7] GKBSBSDY Return `dyn Iterator` instead of `Vec` for `SupportedContent`
  • [8] ZRGSUUIC Add MVP list support
  • [9] C73UJ7ZY Create simple `xilem_html` demo
  • [10] I5IZPMTH Handle empty expressions
  • [11] 4MMVEN5Y Move generated docs inside of parent `docs` module
  • [12] BSJYWOYS Implement MVP Typst embedding
  • [13] BMG4FSHN Add basic `clap` support
  • [14] HEIF2O2E Migrate from `pandoc` to `typst` for AST processing
  • [15] JFJVY57R List `clap` argument IDs
  • [16] A4E5KLI2 Turn arguments into sidebar

Change contents

  • replacement in src/main.rs at line 1
    [3.49][3.0:81]()
    use xilem_html::{document_body, elements as el, App, View, ViewExt, ViewMarker};
    [3.49]
    [3.69]
    pub mod cli;
  • replacement in src/main.rs at line 3
    [3.70][3.70:83](),[3.83][3.0:118]()
    pub mod cli;
    use clap::{parser::ValueSource, CommandFactory};
    use clap_builder::{parser::MatchedArg, util::any_value::AnyValueId};
    [3.70]
    [3.123]
    use clap::parser::ValueSource;
    use clap::{value_parser, ArgMatches, CommandFactory};
  • edit in src/main.rs at line 6
    [3.141]
    [3.0]
    use xilem_html::{document_body, elements as el, App, View, ViewExt, ViewMarker};
  • edit in src/main.rs at line 10
    [3.190][3.190:209]()
    #[derive(Default)]
  • replacement in src/main.rs at line 12
    [3.248][3.119:144]()
    args: Vec<ArgState>,
    [3.248]
    [3.144]
    arg_matches: Result<ArgMatches, clap::Error>,
  • replacement in src/main.rs at line 15
    [3.147][3.147:335]()
    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,
    [3.147]
    [3.248]
    impl Default for AppState {
    fn default() -> Self {
    Self {
    command: String::new(),
    arg_matches: Err(clap::Error::new(clap::error::ErrorKind::TooFewValues)),
    }
    }
  • edit in src/main.rs at line 30
    [3.292][3.292:359](),[3.359][3.336:388]()
    let matches = cli_command.try_get_matches_from(args_iter);
    tracing::debug!("Matches: {:#?}", matches);
  • replacement in src/main.rs at line 32
    [3.455][3.455:570](),[3.570][3.229:280](),[3.229][3.229:280]()
    self.args = if let Ok(matches) = matches {
    matches.args.iter().map(matched_to_state).collect()
    } else {
    Vec::new()
    };
    [3.455]
    [3.571]
    self.arg_matches = cli_command.try_get_matches_from(args_iter);
    tracing::debug!("Matches: {:#?}", self.arg_matches);
  • edit in src/main.rs at line 36
    [3.579][3.579:685]()
    fn matched_to_state(key_value: (&clap::Id, &MatchedArg)) -> ArgState {
    let (key, value) = key_value;
  • replacement in src/main.rs at line 37
    [3.281][3.686:1077](),[3.1077][3.397:403](),[3.397][3.397:403](),[3.403][3.629:631](),[3.629][3.629:631]()
    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>()),
    }
    }
    [3.281]
    [3.631]
    fn arg_item(matches: &ArgMatches, arg: &clap::Arg) -> impl View<AppState> + ViewMarker {
    tracing::debug!("`{:?}`", matches.contains_id("name"));
    let source = if let Some(source) = matches.value_source(arg.get_id().as_str()) {
    match source {
    ValueSource::DefaultValue => "default",
    ValueSource::EnvVariable => "environment",
    ValueSource::CommandLine => "cmdline",
    _ => "todo",
    }
    } else {
    "none"
    };
  • replacement in src/main.rs at line 50
    [3.632][3.1078:1347]()
    fn arg_item(arg: &ArgState) -> impl View<AppState> + ViewMarker {
    let source = match arg.source {
    ValueSource::DefaultValue => "default",
    ValueSource::EnvVariable => "environment",
    ValueSource::CommandLine => "cmdline",
    _ => "todo",
    [3.632]
    [3.1347]
    let type_id = arg.get_value_parser().type_id();
    let type_name = if type_id == value_parser!(String).type_id() {
    "string".to_string()
    } else {
    format!("{:?}", type_id)
  • edit in src/main.rs at line 56
    [3.1354]
    [3.1354]
  • replacement in src/main.rs at line 58
    [3.1368][3.1368:1570]()
    el::h2(arg.name.clone()),
    el::div((
    format!("{:?}", arg.type_id),
    el::div("test").attr("class", "hover_content"),
    ))
    .attr("class", "hoverable"),
    [3.1368]
    [3.1570]
    el::div((type_name, el::div("test").attr("class", "hover_content")))
    .attr("class", "hoverable"),
  • replacement in src/main.rs at line 62
    [3.1611][3.1611:1710]()
    arg.raw_values
    .iter()
    .map(|arg| el::li(arg.clone()))
    [3.1611]
    [3.1710]
    matches
    .get_raw_occurrences(&arg.get_id().as_str())
    .unwrap_or_default()
    .map(|os_strings| {
    el::li({
    os_strings
    .map(|s| s.to_string_lossy().to_string())
    .collect::<Vec<String>>()
    .join(" ")
    })
    })
  • edit in src/main.rs at line 84
    [3.405]
    [3.807]
    let default_matches = ArgMatches::default();
    let arg_matches = state.arg_matches.as_ref().unwrap_or(&default_matches);
    tracing::debug!("{:?}", arg_matches);
  • replacement in src/main.rs at line 89
    [3.921][3.0:114](),[3.114][3.6982:7039](),[3.101][3.161:172](),[3.190][3.161:172](),[3.7039][3.161:172](),[3.161][3.161:172]()
    el::div((
    el::div(state.args.iter().map(arg_item).collect::<Vec<_>>()).attr("id", "sidebar"),
    el::div(docs::test()).attr("id", "content"),
    ))
    [3.921]
    [3.172]
    el::div((el::div(
    MockApp::command()
    .get_opts()
    .filter(|arg| arg_matches.try_contains_id(arg.get_id().as_str()).is_ok())
    .map(|arg| arg_item(&arg_matches, arg))
    .collect::<Vec<_>>(),
    )
    .attr("id", "sidebar"),))
  • edit in docs/test.typ at line 1
    [3.242][2.13749:13771]()
    #let add(x, y) = x + y
  • replacement in Cargo.toml at line 10
    [3.1345][3.1976:2076]()
    clap = { path = "../clap", features = ["derive"] }
    clap_builder = { path = "../clap/clap_builder" }
    [3.1345]
    [3.1345]
    clap = { version = "4.4.8", features = ["derive"] }
    # clap_builder = "4.4.8"
  • replacement in Cargo.lock at line 306
    [3.2160][3.2160:2178]()
    version = "4.4.6"
    [3.2160]
    [3.2321]
    version = "4.4.8"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64"
  • replacement in Cargo.lock at line 316
    [3.2408][3.2408:2426]()
    version = "4.4.6"
    [3.2408]
    [3.2569]
    version = "4.4.8"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc"
  • replacement in Cargo.lock at line 328
    [3.2671][3.2671:2689]()
    version = "4.4.2"
    [3.2671]
    [3.2832]
    version = "4.4.7"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
  • replacement in Cargo.lock at line 340
    [3.2925][3.2925:2943]()
    version = "0.5.1"
    [3.2925]
    [3.7803]
    version = "0.6.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
  • edit in Cargo.lock at line 1026
    [3.3493][3.2316:2333]()
    "clap_builder",
  • edit in Cargo.lock at line 1984
    [3.22874][3.24101:24188]()
    source = "git+https://github.com/typst/typst#3a1e47913d874647e5d8d013a7e21beca96453d6"
  • edit in Cargo.lock at line 2034
    [3.24230][3.24230:24317]()
    source = "git+https://github.com/typst/typst#3a1e47913d874647e5d8d013a7e21beca96453d6"
  • edit in Cargo.lock at line 2074
    [3.23619][3.24838:24925]()
    source = "git+https://github.com/typst/typst#3a1e47913d874647e5d8d013a7e21beca96453d6"
  • edit in Cargo.lock at line 2084
    [3.23828][3.24926:25013]()
    source = "git+https://github.com/typst/typst#3a1e47913d874647e5d8d013a7e21beca96453d6"