Add support for subcommands
Dependencies
- [2]
MT5RA7VYIncrease sidebar density - [3]
ZVDBFCW7Display arguments when input is invalid - [4]
MIY7QPYKRefactor argument handling into a separate file - [5]
C73UJ7ZYCreate simple `xilem_html` demo - [6]
YTW5RB26Refactor argument type handling into enum - [7]
BMG4FSHNAdd basic `clap` support - [8]
LEJN3E4QGenerate more semantic HTML
Change contents
- replacement in src/main.rs at line 46
arg::args_view(state),arg::sidebar(&state), - replacement in src/cli.rs at line 1
use clap::Parser;use clap::{Parser, Subcommand}; - edit in src/cli.rs at line 18
// Subcommand#[command(subcommand)]subcommand: Option<Subcmd>,}#[derive(Subcommand, Debug, Clone, Copy)]pub enum Subcmd {/// First subcommand////// This explanation is also quite long./// It takes up multiple linesOne {#[arg(long)]times: u32,},/// Second subcommand////// Another, even longer explanation./// Would it not be crazy/// if this took up 3 lines??Two {#[arg(short = 'a', long)]amount: i64,}, - replacement in src/arg.rs at line 3
use clap::{Arg, ArgMatches, ValueHint};use clap::{Arg, ArgMatches, Command, ValueHint}; - replacement in src/arg.rs at line 125
fn source(state: &AppState, arg: &Arg) -> impl View<Arg> + ViewMarker {el::span(if let Ok(arg_matches) = state.arg_matches.as_ref() {fn source(arg_matches: Option<&ArgMatches>, arg: &Arg) -> impl View<Arg> + ViewMarker {el::span(if let Some(arg_matches) = arg_matches.as_ref() { - replacement in src/arg.rs at line 162
fn matched_values(state: &AppState, arg: &Arg) -> impl View<Arg> + ViewMarker {fn matched_values(arg_matches: Option<&ArgMatches>, arg: &Arg) -> impl View<Arg> + ViewMarker { - replacement in src/arg.rs at line 164
let arg_matches = state.arg_matches.as_ref().unwrap_or(&default_matches);let arg_matches = arg_matches.unwrap_or(&default_matches); - replacement in src/arg.rs at line 189
fn item(state: &AppState, arg: &Arg) -> impl View<Arg> + ViewMarker {fn item(arg_matches: Option<&ArgMatches>, arg: &Arg) -> impl View<Arg> + ViewMarker { - replacement in src/arg.rs at line 201
source(state, arg),source(arg_matches, arg), - replacement in src/arg.rs at line 205
matched_values(state, arg),matched_values(arg_matches, arg), - replacement in src/arg.rs at line 210
pub fn args_view(state: &mut AppState) -> impl View<AppState> + ViewMarker {el::div(fn args_view(command: &Command, arg_matches: Option<&ArgMatches>) -> impl ViewSequence<AppState> {command.get_opts().map(|arg| {Adapt::new(|_state, _thunk| {// TODO: actually re-compute this valueMessageResult::Nop},item(arg_matches, arg),)}).collect::<Vec<_>>()}pub fn sidebar(state: &AppState) -> impl View<AppState> + ViewMarker {let arg_matches = state.arg_matches.as_ref().ok();el::div((args_view(&state.command, arg_matches), - replacement in src/arg.rs at line 231
.get_opts().map(|arg| {Adapt::new(|_state, _thunk| {// TODO: actually re-compute this valueMessageResult::Nop},item(state, arg),.get_subcommands().map(|subcommand| {args_view(subcommand,arg_matches.and_then(|arg_matches| {arg_matches.subcommand_matches(subcommand.get_name())}), - replacement in src/arg.rs at line 241
)))