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
  • 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
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 19 Aug 18, 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 97 Jul 31, 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 550 Nov 23, 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 16 Aug 6, 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 34 Oct 15, 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 6 May 12, 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 19 Sep 8, 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
Rust for the Windows App SDK

Rust for the Windows App SDK The windows-app crate makes the Windows App SDK (formerly known as Project Reunion) available to Rust developers.

Microsoft 212 Nov 22, 2022
Adds size optimizations to any Perseus app automatically.

Perseus Size Optimization Plugin WARNING: Until Perseus #66 is fixed, this plugin can actually increase overall binary size! Once that issue is fixed

arctic_hen7 6 Aug 14, 2022
The working code for my Safe Pay app - check out my tutorial!

Safe Pay Tutorial This repository contains the source code for my blog post Using PDAs and SPL Token in Anchor. The code contains the following: Solan

Daniel Pyrathon 39 Aug 28, 2022
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 Nov 29, 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 20 Sep 28, 2022