veks-completion-derive 2.3.0
“Derive macro for the veks-completion CLI framework (the in-tree clap replacement)”
Release published within seven daysRust proc macro entrypoint
SHA-2567293d233ac1fb7ec7b84e9e9b72860ce89ade8e574d0ef1e5ea9aca1b9e9185a
MaleculeO(S)H(Db)Md
Evidence
1// Copyright (c) Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! `#[derive(VeksCli)]` — generates the [`veks_completion::VeksCli`] impl for a
5//! command/args struct or a subcommand enum. From one annotated declaration it
6//! produces the `CommandSpec` (which drives parsing, help, and completion) and
7//! the typed extraction from a `ParsedArgs`. This is the in-tree replacement
8//! for clap's derive.
9//!
10//! ## Structs (a command's arguments)
11//! - a field with `#[arg(long)]`/`#[arg(short)]` is an **option**;
12//! - a `bool` field is a **flag** (no value); …
19:26… )
20//! Each variant becomes a subcommand: unit ⇒ no args, `V(ArgsStruct)` ⇒ delegate,
21//! `V { … }` ⇒ inline fields.
22
23use proc_macro::TokenStream;
24use proc_macro2::TokenStream as TS2;
25use quote::quote;
26use syn::{
27 punctuated::Punctuated, token::Comma, Attribute, Data, DeriveInput, Expr, ExprLit, Field,
28 Fields, Lit, Meta, Type,
29};
30
31#[proc_macro_derive(VeksCli, attributes(arg, command))]
32pub fn derive_veks_cli(input: TokenStre …
330:2… None
331}
332
333fn ident_to_long(ident: &syn::Ident) -> String {
334 ident.to_string().trim_start_matches("r#").replace('_', "-")
335}
336
337fn pascal_to_kebab(ident: &syn::Ident) -> String {
338 let s = ident.to_string();
339 let mut out = String …
405:53… e subcommand required; relax
406 // that here so the parent command may stand alone.
407 spec_stmts.push(quote! {
408 …
672:64… Args)
673 -> ::std::result::Result<Self, ::veks_completion::cli::ParseError>
674 {
675 ::std::result::Result::Ok(#name { #(#inits),* })
676 }
677 }
⋯4 lines
No evidence locations were recorded for this file. Raw result