Provides a wrapper to deserialize clap app using serde.

Overview

clap-serde

Provides a wrapper to deserialize clap app using serde.

Crates.io License License API Reference

toml

(CLAP_TOML) .expect("parse failed") .into(); assert_eq!(app.get_name(), "app_clap_serde"); assert_eq!(app.get_about(), Some("test-clap-serde"));">
const CLAP_TOML: &'static str = r#"
name = "app_clap_serde"
version = "1.0"
author = "toml_tester"
about = "test-clap-serde"
[subcommands]
sub1 = { about = "subcommand_1" }
[subcommands.sub2]
about = "subcommand_2"
[args]
apple = { short = "a" }
banana = { short = "b", long = "banana", aliases = ["musa_spp"] }
[groups]
fruit = { args = ["apple", "banana"] }
"#;

let app: clap::App = toml::from_str::
   
    (CLAP_TOML)
    .expect("parse failed")
    .into();
assert_eq!(app.get_name(), "app_clap_serde");
assert_eq!(app.get_about(), Some("test-clap-serde"));

   

json

(CLAP_JSON) .expect("parse failed") .into(); assert_eq!(app.get_name(), "app_clap_serde"); assert_eq!(app.get_about(), Some("test-clap-serde"));">
const CLAP_JSON: &'static str = r#"{
"name" : "app_clap_serde", 
"version" : "1.0" , 
"author" : "json_tester", 
"about" : "test-clap-serde", 
"subcommands" : {
    "sub1" : {"about" : "subcommand_1"},
    "sub2" : {"about" : "subcommand_2"}},
"args" : {
    "apple" : {"short" : "a" },
    "banana" : {"short" : "b", "long" : "banana", "aliases" : [ "musa_spp" ]}
},
"groups" : {
    "fruit" : { "args" : ["apple", "banana"] }
}
}"#;

let app: clap::App = serde_json::from_str::
   
    (CLAP_JSON)
    .expect("parse failed")
    .into();
assert_eq!(app.get_name(), "app_clap_serde");
assert_eq!(app.get_about(), Some("test-clap-serde"));

   

yaml

clap-serde provides a Deserializer for yaml. This requires yaml feature.

const CLAP_YAML: &'static str = r#"
name: app_clap_serde
version : "1.0"
about : yaml_support!
author : yaml_supporter

args:
    - apple : 
        - short: a
    - banana:
        - short: b
        - long: banana
        - aliases :
            - musa_spp

subcommands:
    - sub1: 
        - about : subcommand_1
    - sub2: 
        - about : subcommand_2

"#;
let yaml = yaml_rust::Yaml::Array(yaml_rust::YamlLoader::load_from_str(CLAP_YAML).expect("not a yaml"));
let app = clap_serde::yaml_to_app(&yaml).expect("parse failed from yaml");
assert_eq!(app.get_name(), "app_clap_serde");

features

env

Enables env feature in clap.

yaml

Enables to use yaml. Enabled by default.

color

Enablse color feature in clap.

(key case settings)

Settings names format for keys and AppSettings.

snake-case-key

snake_case. Enabled by default.

pascal-case-key

PascalCase. Same as variants name in enum at AppSettings.

kebab-case-key

kebab-case.

Comments
  • Only expose the Settings you have to

    Only expose the Settings you have to

    We are looking at dropping settings (see https://github.com/clap-rs/clap/issues/2717). Limiting your support for them would ease the transition when this happens (data model transitions are a hard thing to document appropriately)

    opened by epage 5
  • Should 'required = false' in arg. allow default value to be undefined?

    Should 'required = false' in arg. allow default value to be undefined?

    If argument is set as required = false it seems to have no impact on argument rendered as an 'option'?

    Only way I was able to add optional flags was to give them default_value and hide it from the --help with hide_default_value = true

    I was testing with this toml:

    name = "Service provider X"
    version = "0.1"
    author = "author"
    about = "Commands to invoke service provider scripts."
    
    [subcommands.node]
    about = "Commands for managing server nodes" 
    subcommand_required = true
    
    [subcommands.node.subcommands.create]
    about = "Create new server nodes"
    arg_required_else_help = true
    
    [subcommands.node.subcommands.create.args.name]
    help = "Node name within the group"
    forbid_empty_values = true
    
    [subcommands.node.subcommands.create.args.group]
    # default_value = "something"
    # hide_default_value = true
    short = "g"
    long = "group"
    help = "Node group name"
    

    cmd: target/debug/test node create FirstArg --group GroupName

    Above fails when --group is defined, works without the flag though. Starts working as expected with or without --group flag when default_value = "something" is uncommented.

    Not a big issue, I was just curious. Thank you for your work on this, seems to be the only way to extend clap commands runtime.

    opened by pintoflager 4
  • Use arrays for ordered items

    Use arrays for ordered items

    Currently subcommands and args are objects in the data model. A lot of serialization sources consider the objects to have an undefined order but order of these is important. Rather than relying on implementation details of the serializers (and tools mucking with the raw data), I'd recommend switching these to arrays like in the old clap YAML support

    name: myapp
    version: "1.0"
    author: Kevin K. <[email protected]>
    about: Does awesome things
    args:
        - config:
            short: c
            long: config
            value_name: FILE
            help: Sets a custom config file
            takes_value: true
        - INPUT:
            help: Sets the input file to use
            required: true
            index: 1
        - verbose:
            short: v
            multiple: true
            help: Sets the level of verbosity
    subcommands:
        - test:
            about: controls testing features
            version: "1.3"
            author: Someone E. <[email protected]>
            args:
                - debug:
                    short: d
                    help: print debug information
    
    opened by epage 4
  • Dual license?

    Dual license?

    The standard approach in the Rust ecosystem is to dual license

    See https://rust-lang.github.io/api-guidelines/necessities.html#c-permissive

    Doing so would make it easier to become a more semi-official clap project (even move into the clap org if you want). If interested, the earlier the done, the easier this is.

    opened by epage 1
  • Update to 3.1

    Update to 3.1

    A lot of things have changed since clap 3.0. This crate needs to catch up.

    TODO

    • [x] App to Command
    • [x] Add new flags for builder methods to Command
    • [ ] Add new flags for builder methods to Arg
    • [ ] Deprecations
    opened by aobatact 0
  • Ver 0.3

    Ver 0.3

    Changes at ver 0.3

    • Added more keys in App
    • Added more keys in Arg
    • Change the feature name of case settings.
    • Add support to use the non snake_case key names.
    opened by aobatact 0
  • Support for context-specific `App` functions

    Support for context-specific `App` functions

    App::help_heading applies to all future args being added. We expect to add more like this (App::next_display_order, `App::env_prefix).

    The challenge will be to fit it in the data model.

    opened by epage 4
  • Serialize support

    Serialize support

    This was requested in clap, see https://github.com/clap-rs/clap/issues/918

    Other benefits

    • Insights into clap building by allowing dumping before and after to see what changed
    • Another way of providing insight into the derive API compared to cargo expand
    • Hopefully help people detect some level of breaking changes (especially for the more magical derive API)
    opened by epage 0
Owner
null
Serde support for (rusty_)v8

serde_v8 Serde support for (rusty_)v8 WIP: see denoland/deno#9540 TODO Experiment with KeyCache to optimize struct keys Experiment with external v8 st

Aaron O'Mullan 13 Nov 28, 2022
dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle!

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle (such as rewriting/refactroing your DM code).

SS220 20 Dec 13, 2022
This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you specified.

prae This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you spec

null 96 Dec 4, 2022
todo-or-die provides procedural macros that act as checked reminders.

todo-or-die provides procedural macros that act as checked reminders.

David Pedersen 552 Dec 24, 2022
Provides two APIs for easily cancelling futures, with the option to fallback to a timeout cancellation

tokio-context Provides two different methods for cancelling futures with a provided handle for cancelling all related futures, with a fallback timeout

Peter Farr 18 Dec 27, 2022
global allocator that provides hooks for tracking allocation events

tracking-allocator A GlobalAlloc-compatible allocator implementation that provides the ability to track allocation events. examples As allocators are

Toby Lawrence 39 Dec 22, 2022
`fugit` provides a comprehensive library of `Duration` and `Instant` for the handling of time in embedded systems, doing all it can at compile time.

fugit fugit provides a comprehensive library of Duration and Instant for the handling of time in embedded systems, doing all it can at compile time. T

Emil Fresk 40 Oct 2, 2022
cooptex provides deadlock-free Mutexes.

cooptex provides deadlock-free Mutexes. The [CoopMutex::lock] method wraps the [std::sync::Mutex] return value with a Result that will request

Shelby Doolittle 12 Oct 10, 2022
Provides a Suricata Eve output for Kafka with Suricate Eve plugin

Suricata Eve Kafka Output Plugin for Suricata 6.0.x This plugin provides a Suricata Eve output for Kafka. Base on suricata-redis-output: https://githu

Center 7 Dec 15, 2022
A (mostly) drop-in replacement for Rust's Result that provides backtrace support

Errant A (mostly) drop-in replacement for Rust's Result that provides backtrace support. Please note that Errant is still very early in development an

Joshua Barretto 17 Dec 26, 2022
This repository provides an emulator for iterated prisoner's dilemma.

Iterated Prisoner's Dilemma Emulator Name This repository provides an emulator for iterated prisoner's dilemma. Description You can run the program by

tison 3 Jan 28, 2022
Memory.lol - a tiny web service that provides historical information about social media accounts

memory.lol Overview This project is a tiny web service that provides historical information about social media accounts. It can currently be used to l

Travis Brown 317 Jul 12, 2023
Thin wrapper around starship.rs to format kakoune status line

kakship is just a thin wrapper around starship to format the status line of kakoune and is meant to be used with the included kakoune script kakship.kak.

Eric Burghard 15 Jun 7, 2022
A lightweight Discord wrapper made in Tauri

Discord-Tauri is a work in progress lightweight wrapper for Discord.

null 104 Dec 20, 2022
A rust wrapper for the spam protection API

SpamProtection-rs Table of contents About Supported Rust version Features How to use Credits License About This repo has been shifted to the official

cyberknight777 28 Aug 5, 2022
A Rust wrapper for the SponsorBlock API.

sponsor-block A Rust wrapper for the SponsorBlock API, which you can find complete documentation for here. Uses SponsorBlock data licensed under CC BY

Zacchary Dempsey-Plante 8 Nov 19, 2022
API wrapper for the tankerkönig api

tankerkoenig-rs API wrapper for the tankerkoenig-api written in rust. Gives you ready deserialized structs and a easy to use and strictly typed api. I

Jonathan 2 Feb 27, 2022
FFI wrapper around cfitsio in Rust

rust-fitsio FFI wrapper around cfitsio in Rust Installation fitsio supports versions of cfitsio >= 3.08. cfitsio must be compiled with reentrant suppo

Simon Walker 22 Dec 24, 2022
Wrapper library for utilizing DigitalOcean API v2 in Rust

doapi-rs Wrapper library for utilizing DigitalOcean API v2 in Rust Disclaimer This library is in alpha - it may do anything up to, and including, eati

Kevin K. 30 Nov 5, 2022