6 releases

0.1.5 Apr 27, 2023
0.1.4 Jan 20, 2023
0.1.2 Dec 27, 2022
0.1.0 Nov 30, 2022

#2332 in Parser implementations

Download history 11/week @ 2024-02-26 5/week @ 2024-03-04 30/week @ 2024-03-11 22/week @ 2024-04-01

53 downloads per month
Used in wasm-deploy

MIT license

30KB
745 lines

interactive-parse

An interactive parser for JsonSchema types.


Demo



Usage


    // Make sure you add these derives to your type
    #[derive(JsonSchema, Deserialize, Debug)]
    struct Git {
        subcommand: SubCommand,
        /// Using doc comments like these will add hints to the prompt
        arg: String
    }

    #[derive(JsonSchema, Deserialize, Debug)]
    enum SubCommand {
        Commit {
            /// interactive-parse automatically handles
            /// any type that you can throw at it,
            /// like options
            message: Option<String>
        },
        Clone {
            /// vecs, and more!
            address: Vec<String>
        }
    }

    // Bring the relevant traits into scope
    use interactive_parse::{InteractiveParseObj, InteractiveParseVal};

    fn main() {
        // Parse the type to an object
        let git = Git::parse_to_obj().unwrap();

        // Or to a json value
        let value = Git::parse_to_val().unwrap();
        
        println!("{:?}", git);   
    }

Cool features


hitting Esc during a multi-stage prompt will undo the last input and revert to the previous sub prompt. This feature is new and may skip back multiple prompts in some cases, but still very useful. Do to the recursive nature of this crate, undoing is very non-trivial.


Looking for others to contribute


This is a simple approach at getting JsonSchema types to parse interactively using inquire. If you make improvements to this please submit a PR, and if you have any issues or bugs please submit an issue. I'm currently actively maintaining this project as a personal development tool.

In particular, this crate needs proper error handling. In most cases the crate will panic if it encounters an issue parsing. This is not ideal and could definitely be improved.

In particular, this crate needs proper error handling. In most cases the crate will panic if it encounters an issue parsing. This is not ideal and should definitely be improved.


Dependencies

~3–13MB
~136K SLoC